Why does sleep mode generate additional objects when matching many-to-many relationships?

I am making an application now, and I started by creating a DB schema that looks like this:

Database schema

There are several tables (users_groups_maps, articles_tags_maps reports_articles, favorite_articles and browse_later_articles), which are a multiple exemption from many. I created the reverse configuration file and started the reverse engineer so that I can extract Java classes from it (annotations, JDK 5 and EJB3, which leads to javax.persistence. * Comments).

Basic tables (e.g. alerts, users) are very good (there are fields like

private Set<BrowseLaterArticles> browseLaterArticleses = new HashSet<BrowseLaterArticles>(0); 

but I think it's just fine - I'm new to sleep mode).

However, the problem (I think) begins with this many-to-many relationship (for example, the UserGroupsMaps constructor looks like this:

 public UsersGroupsMaps(UsersGroupsMapsId id, Users users, Groups groups) { this.id = id; this.users = users; this.groups = groups; } 

where UserGroupsMapsId is a wrapper for a pair of userId and groupId)

Am I mistaken or should it be encoded differently? I know there is ManyToMany annotation, why is sleep mode not used?

// Besides, I have not related to hibernate issues - in the comments and private_messages, there are fields parent__id, which should be in the same table. I created foreign keys for my own tables, but I'm not sure if this is correct? What should it look like? In this mode, sleep mode generates two fields with the same name: personal comment comments; in the comment class.

Regards, Marcin

+4
source share
2 answers

Your hibernation mapping is messed up somewhere. Hibernate gives you the option of not creating objects for many-to-many join objects if there are no additional columns in this table. Guess you are using the eclipse hibernate plugin? I would check the settings of the code generator to find out if you can say this not to create this object.

0
source

so that "sleep tools" / "Jboss tools" generate many, many annotations in your bean classes, you need to use simple mapping tables. In these mapping tables, there should only be columns for both foreign keys, which must be a combined primary key.

0
source

Source: https://habr.com/ru/post/1380884/


All Articles