Доброго времени суток!
Уже несколько недель, безуспешно пытаюсь решить проблему с хибернейтом ((
Перечитал кучу документации, прогуглил все, что только можно…
Подскажите, пожалуйста, в чем ошибка? Что я делаю не так?
Схема БД:
Маппинг:
(для генерации геттеров/сеттеров использую библиотеку lombok)
User.java
Copy Source | Copy HTML
- @Entity
- @Table(name = "users")
- public @Data class User
- {
-
- // Base Mapping
-
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- @Column(name = "user_id")
- @Getter @Setter Long user_id;
-
- @Column(name = "user_name")
- private @Getter @Setter String user_name;
-
- @Column(name = "login")
- private @Getter @Setter String login;
-
- @Column(name = "password")
- private @Getter @Setter String password;
-
- // Releations Mapping
-
- // Releations With Project
-
- @ManyToMany(cascade={CascadeType.ALL})
- @JoinTable(name="users_on_projects",
- joinColumns=@JoinColumn(name="user_id"),
- inverseJoinColumns=@JoinColumn(name="project_id") )
- private @Getter @Setter List projects = new Vector();
@OneToMany
@JoinTable(name="users_on_projects",
joinColumns=@JoinColumn(name="user_id"),
inverseJoinColumns=@JoinColumn(name="users_on_projects_id") )
private @Getter @Setter List intervals = new Vector();
}
Project.java
Copy Source | Copy HTML
- @Entity
- @Table(name = "projects")
- public @Data class Project
- {
-
- // Base Mapping
-
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- @Column(name ="project_id")
- private @Getter @Setter Long project_id;
-
- @Column(name ="project_name")
- private @Getter @Setter String project_name;
-
-
- // Releations Mapping
-
- // Releations With User
-
- @ManyToMany(cascade={CascadeType.ALL})
- @JoinTable(name="users_on_projects",
- joinColumns=@JoinColumn(name="project_id"),
- inverseJoinColumns=@JoinColumn(name="user_id") )
- private @Getter @Setter List users = new Vector();
@OneToMany
@JoinTable(name="users_on_projects",
joinColumns=@JoinColumn(name="project_id"),
inverseJoinColumns=@JoinColumn(name="users_on_projects_id") )
private @Getter @Setter List intervals = new Vector();
Interval.java
Copy Source | Copy HTML
- @Entity
- @Table(name = "intervals")
- public class Interval
- {
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- @Column(name = "interval_id")
- @Getter @Setter Long interval_id;
-
- @Column(name ="start_time")
- private @Setter @Getter
- @Temporal(javax.persistence.TemporalType.TIMESTAMP)
- Date start_time;
-
- @Column(name ="finish_time")
- private @Setter @Getter
- @Temporal(javax.persistence.TemporalType.TIMESTAMP)
- Date FinishTime;
-
-
- @ManyToOne(cascade={CascadeType.ALL})
- @JoinTable(name="users_on_projects",
- joinColumns=@JoinColumn(name="users_on_projects_id"),
- inverseJoinColumns=@JoinColumn(name="user_id") )
- private @Getter @Setter User user;
-
-
- @JoinTable(name="users_on_projects",
- joinColumns=@JoinColumn(name="users_on_projects_id"),
- inverseJoinColumns=@JoinColumn(name="project_id") )
- private @Getter @Setter
- @ManyToOne
- Project project;
-
-
- @ManyToOne(cascade = CascadeType.ALL)
- @JoinColumn(name="interval_type_id")
- private @Getter @Setter IntervalType intervalType;
-
- }
IntervalType.java
Copy Source | Copy HTML
- @Entity
- @Table(name = "interval_type")
- public class IntervalType
- {
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- @Column(name = "interval_type_id")
- @Getter @Setter Long interval_type_id;
-
- @Column(name = "interval_type_name")
- private @Getter @Setter String interval_type_name;
- }
Заранее благодарен!
UPD: На чтение все заработало.
Но, осталась проблема с записью интервалов (intervals).. Подскажите, что не так ?..
Корректный маппинг файла User.java :
Copy Source | Copy HTML
- @Entity
- @Table(name = "users")
- public @Data class User
- {
-
- // Base Mapping
-
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- @Column(name = "user_id")
- @Getter @Setter Long user_id;
-
- @Column(name = "user_name")
- private @Getter @Setter String user_name;
-
- @Column(name = "login")
- private @Getter @Setter String login;
-
- @Column(name = "password")
- private @Getter @Setter String password;
-
- // Releations Mapping
-
- // Releations With Project
-
- @ManyToMany(cascade={CascadeType.ALL})
- @JoinTable(name="users_on_projects",
- joinColumns=@JoinColumn(name="user_id"),
- inverseJoinColumns=@JoinColumn(name="project_id") )
- private @Getter @Setter List projects = new Vector();
<
@OneToMany
@JoinTable(name="intervals",
joinColumns=@JoinColumn(name="users_on_projects_id"),
inverseJoinColumns=@JoinColumn(name="interval_id") )
private @Getter @Setter List intervals = new Vector();
}