Spring+Hibernate Unknown column 'users0_.task_id' in 'field list'
up vote
0
down vote
favorite
I'm newbie in Spring and Hibernate. I want create OneToMany relation beetwen two tables User and Task. I think it is stupid mistake in my code but i can't find where. This is my sql code:
CREATE TABLE IF NOT EXISTS `tms`.`task` (
`task_id` INT(11) NOT NULL AUTO_INCREMENT,
`date` DATETIME NULL DEFAULT NULL,
`hour` VARCHAR(45) NULL DEFAULT NULL,
`time` DOUBLE NULL DEFAULT NULL,
`task` VARCHAR(45) NULL DEFAULT NULL,
`description` TEXT NULL DEFAULT NULL,
PRIMARY KEY (`task_id`))
ENGINE = InnoDB
AUTO_INCREMENT = 4
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci
CREATE TABLE IF NOT EXISTS `tms`.`user` (
`user_id` INT(11) NOT NULL,
`name` VARCHAR(45) NULL DEFAULT NULL,
`login` VARCHAR(45) NULL DEFAULT NULL,
`password` VARCHAR(45) NULL DEFAULT NULL,
PRIMARY KEY (`user_id`),
CONSTRAINT `fk_task`
FOREIGN KEY (`user_id`)
REFERENCES `tms`.`task` (`task_id`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci
User entity:
@Entity
@Table(name="user")
public class User {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="user_id")
private int id;
/* other fields */
@ManyToOne
@JoinColumn(name="task_id")
private Task task;
Task entity:
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="task_id")
private int id;
@Column(name="date")
private Date date;
@Column(name="hour")
private double hour;
@Column(name="description")
private String description;
@Column(name="time")
private double time;
@OneToMany(mappedBy="task")
private List<User> users;
I want get from database TASK object with all USER. Can`t understand the field 'users0_.task_id' exist in the database. I think it is default hibernate naming. Please look at my database because don't have certainty about it.
This is my code which i want fetch data from db:
DAO:
@Override
public Task getTask(int id) {
Session session = sessionFactory.getCurrentSession();
Task task = session.get(Task.class, id);
return task;
}
Service:
@Transactional
@Override
public Task getTask(int id) {
Task task = userDAO.getTask(id);
Hibernate.initialize(task.getUsers());
return task;
}
My controller:
Task task = userService.getTask(1);
and error:
java.sql.SQLSyntaxErrorException: Unknown column 'users0_.task_id' in
'field list'
mysql spring hibernate
add a comment |
up vote
0
down vote
favorite
I'm newbie in Spring and Hibernate. I want create OneToMany relation beetwen two tables User and Task. I think it is stupid mistake in my code but i can't find where. This is my sql code:
CREATE TABLE IF NOT EXISTS `tms`.`task` (
`task_id` INT(11) NOT NULL AUTO_INCREMENT,
`date` DATETIME NULL DEFAULT NULL,
`hour` VARCHAR(45) NULL DEFAULT NULL,
`time` DOUBLE NULL DEFAULT NULL,
`task` VARCHAR(45) NULL DEFAULT NULL,
`description` TEXT NULL DEFAULT NULL,
PRIMARY KEY (`task_id`))
ENGINE = InnoDB
AUTO_INCREMENT = 4
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci
CREATE TABLE IF NOT EXISTS `tms`.`user` (
`user_id` INT(11) NOT NULL,
`name` VARCHAR(45) NULL DEFAULT NULL,
`login` VARCHAR(45) NULL DEFAULT NULL,
`password` VARCHAR(45) NULL DEFAULT NULL,
PRIMARY KEY (`user_id`),
CONSTRAINT `fk_task`
FOREIGN KEY (`user_id`)
REFERENCES `tms`.`task` (`task_id`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci
User entity:
@Entity
@Table(name="user")
public class User {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="user_id")
private int id;
/* other fields */
@ManyToOne
@JoinColumn(name="task_id")
private Task task;
Task entity:
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="task_id")
private int id;
@Column(name="date")
private Date date;
@Column(name="hour")
private double hour;
@Column(name="description")
private String description;
@Column(name="time")
private double time;
@OneToMany(mappedBy="task")
private List<User> users;
I want get from database TASK object with all USER. Can`t understand the field 'users0_.task_id' exist in the database. I think it is default hibernate naming. Please look at my database because don't have certainty about it.
This is my code which i want fetch data from db:
DAO:
@Override
public Task getTask(int id) {
Session session = sessionFactory.getCurrentSession();
Task task = session.get(Task.class, id);
return task;
}
Service:
@Transactional
@Override
public Task getTask(int id) {
Task task = userDAO.getTask(id);
Hibernate.initialize(task.getUsers());
return task;
}
My controller:
Task task = userService.getTask(1);
and error:
java.sql.SQLSyntaxErrorException: Unknown column 'users0_.task_id' in
'field list'
mysql spring hibernate
The message says it all: you need a task_id column in the user table to reference the task that the user is assigned to. You currently use the user_if as a foreign key to the task, which doesn't make sense.
– JB Nizet
yesterday
@JBNizet Thanks a lot. It's work!
– Dawid Pawka
yesterday
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm newbie in Spring and Hibernate. I want create OneToMany relation beetwen two tables User and Task. I think it is stupid mistake in my code but i can't find where. This is my sql code:
CREATE TABLE IF NOT EXISTS `tms`.`task` (
`task_id` INT(11) NOT NULL AUTO_INCREMENT,
`date` DATETIME NULL DEFAULT NULL,
`hour` VARCHAR(45) NULL DEFAULT NULL,
`time` DOUBLE NULL DEFAULT NULL,
`task` VARCHAR(45) NULL DEFAULT NULL,
`description` TEXT NULL DEFAULT NULL,
PRIMARY KEY (`task_id`))
ENGINE = InnoDB
AUTO_INCREMENT = 4
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci
CREATE TABLE IF NOT EXISTS `tms`.`user` (
`user_id` INT(11) NOT NULL,
`name` VARCHAR(45) NULL DEFAULT NULL,
`login` VARCHAR(45) NULL DEFAULT NULL,
`password` VARCHAR(45) NULL DEFAULT NULL,
PRIMARY KEY (`user_id`),
CONSTRAINT `fk_task`
FOREIGN KEY (`user_id`)
REFERENCES `tms`.`task` (`task_id`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci
User entity:
@Entity
@Table(name="user")
public class User {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="user_id")
private int id;
/* other fields */
@ManyToOne
@JoinColumn(name="task_id")
private Task task;
Task entity:
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="task_id")
private int id;
@Column(name="date")
private Date date;
@Column(name="hour")
private double hour;
@Column(name="description")
private String description;
@Column(name="time")
private double time;
@OneToMany(mappedBy="task")
private List<User> users;
I want get from database TASK object with all USER. Can`t understand the field 'users0_.task_id' exist in the database. I think it is default hibernate naming. Please look at my database because don't have certainty about it.
This is my code which i want fetch data from db:
DAO:
@Override
public Task getTask(int id) {
Session session = sessionFactory.getCurrentSession();
Task task = session.get(Task.class, id);
return task;
}
Service:
@Transactional
@Override
public Task getTask(int id) {
Task task = userDAO.getTask(id);
Hibernate.initialize(task.getUsers());
return task;
}
My controller:
Task task = userService.getTask(1);
and error:
java.sql.SQLSyntaxErrorException: Unknown column 'users0_.task_id' in
'field list'
mysql spring hibernate
I'm newbie in Spring and Hibernate. I want create OneToMany relation beetwen two tables User and Task. I think it is stupid mistake in my code but i can't find where. This is my sql code:
CREATE TABLE IF NOT EXISTS `tms`.`task` (
`task_id` INT(11) NOT NULL AUTO_INCREMENT,
`date` DATETIME NULL DEFAULT NULL,
`hour` VARCHAR(45) NULL DEFAULT NULL,
`time` DOUBLE NULL DEFAULT NULL,
`task` VARCHAR(45) NULL DEFAULT NULL,
`description` TEXT NULL DEFAULT NULL,
PRIMARY KEY (`task_id`))
ENGINE = InnoDB
AUTO_INCREMENT = 4
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci
CREATE TABLE IF NOT EXISTS `tms`.`user` (
`user_id` INT(11) NOT NULL,
`name` VARCHAR(45) NULL DEFAULT NULL,
`login` VARCHAR(45) NULL DEFAULT NULL,
`password` VARCHAR(45) NULL DEFAULT NULL,
PRIMARY KEY (`user_id`),
CONSTRAINT `fk_task`
FOREIGN KEY (`user_id`)
REFERENCES `tms`.`task` (`task_id`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci
User entity:
@Entity
@Table(name="user")
public class User {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="user_id")
private int id;
/* other fields */
@ManyToOne
@JoinColumn(name="task_id")
private Task task;
Task entity:
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="task_id")
private int id;
@Column(name="date")
private Date date;
@Column(name="hour")
private double hour;
@Column(name="description")
private String description;
@Column(name="time")
private double time;
@OneToMany(mappedBy="task")
private List<User> users;
I want get from database TASK object with all USER. Can`t understand the field 'users0_.task_id' exist in the database. I think it is default hibernate naming. Please look at my database because don't have certainty about it.
This is my code which i want fetch data from db:
DAO:
@Override
public Task getTask(int id) {
Session session = sessionFactory.getCurrentSession();
Task task = session.get(Task.class, id);
return task;
}
Service:
@Transactional
@Override
public Task getTask(int id) {
Task task = userDAO.getTask(id);
Hibernate.initialize(task.getUsers());
return task;
}
My controller:
Task task = userService.getTask(1);
and error:
java.sql.SQLSyntaxErrorException: Unknown column 'users0_.task_id' in
'field list'
mysql spring hibernate
mysql spring hibernate
asked yesterday
Dawid Pawka
1
1
The message says it all: you need a task_id column in the user table to reference the task that the user is assigned to. You currently use the user_if as a foreign key to the task, which doesn't make sense.
– JB Nizet
yesterday
@JBNizet Thanks a lot. It's work!
– Dawid Pawka
yesterday
add a comment |
The message says it all: you need a task_id column in the user table to reference the task that the user is assigned to. You currently use the user_if as a foreign key to the task, which doesn't make sense.
– JB Nizet
yesterday
@JBNizet Thanks a lot. It's work!
– Dawid Pawka
yesterday
The message says it all: you need a task_id column in the user table to reference the task that the user is assigned to. You currently use the user_if as a foreign key to the task, which doesn't make sense.
– JB Nizet
yesterday
The message says it all: you need a task_id column in the user table to reference the task that the user is assigned to. You currently use the user_if as a foreign key to the task, which doesn't make sense.
– JB Nizet
yesterday
@JBNizet Thanks a lot. It's work!
– Dawid Pawka
yesterday
@JBNizet Thanks a lot. It's work!
– Dawid Pawka
yesterday
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53343676%2fspringhibernate-unknown-column-users0-task-id-in-field-list%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The message says it all: you need a task_id column in the user table to reference the task that the user is assigned to. You currently use the user_if as a foreign key to the task, which doesn't make sense.
– JB Nizet
yesterday
@JBNizet Thanks a lot. It's work!
– Dawid Pawka
yesterday