Answer the question
In order to leave comments, you need to log in
Hibernate ORM: Mapping issue
Good day!
For several weeks, I have been unsuccessfully trying to solve the problem with hibernate ((I
re-read a bunch of documentation, googled everything I could ...
Tell me, please, what is the mistake? What am I doing wrong?
DB schema:
Mapping:
(to generate getters/setters I use the lombok library)
User.java
Copy Source | Copy HTML
@OneToMany
@JoinTable(name="users_on_projects",
[email protected](name="user_id"),
[email protected](name="users_on_projects_id") )
private @Getter @Setter List intervals = new Vector();
}
Project.java
Copy Source | Copy HTML
@OneToMany
@JoinTable(name="users_on_projects",
[email protected](name="project_id"),
[email protected](name="users_on_projects_id") )
private @Getter @Setter List intervals = new Vector();
Interval.java
Copy Source | Copy HTML
IntervalType.java
Copy Source | Copy HTML
Заранее благодарен!
UPD: На чтение все заработало.
Но, осталась проблема с записью интервалов (intervals).. Подскажите, что не так ?..
Корректный маппинг файла User.java :
Copy Source | Copy HTML
<
@OneToMany
@JoinTable(name="intervals",
[email protected](name="users_on_projects_id"),
[email protected](name="interval_id") )
private @Getter @Setter List intervals = new Vector();
}
Answer the question
In order to leave comments, you need to log in
I can recommend to you to simplify communications by adding classes. For example, in your case, make the UserOnProject class and I think the problem will be resolved immediately. And later, perhaps this class will also come in handy for new attributes.
And in general, hibernate eats a lot of memory. Very dofiga, compared to the same solutions on django, for example, just orders of magnitude. Over time, I think about using something from NoSQL, the same MongoDB, to see what happens ...
Sorry for the crooked suggestion, but you can do this:
Install Spring Roo, configure it for our database, then say database reverse engineer
Or NetBins can also generate database mappings.
I'm sorry if I'm wrong (I haven't dealt with Gibernate for a very long time), but shouldn't mapping classes have a default constructor?
Problem solved, thank you all for your help!
Correct description of the relationship
I was thinking, maybe write an article about mapping complex relationships?
And about mapping on annotations / a simple example? (like there isn't one) Users--->Intervals
@OneToMany
@JoinTable(name="intervals",
[email protected](name="users_on_projects_id"),
[email protected](name="interval_id") )
private @Getter @Setter List intervals = new Vector();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question