Hibernate - @ManyToMany with additional fields in mapping entity?

Look at Cascading and Table inheritance. For example the code below would represent three tables. A Company Table, a Role table with a CATG and a User table.

The role table would use single table inheritance where the CATG would be managed by hibernate and hibernate would create the right class based on the CATG column value and the mapping. And cascading would insert the role at the same time as the user.

Look at Cascading and Table inheritance. For example the code below would represent three tables. A Company Table, a Role table with a CATG and a User table.

The role table would use single table inheritance where the CATG would be managed by hibernate and hibernate would create the right class based on the CATG column value and the mapping. And cascading would insert the role at the same time as the user. @Table( name = "USER" ) Public User { @ManyToOne( fetch = FetchType.

LAZY ) @JoinColumn( cascade = CascadeType. ALL, name="ROLE_NAME" ) private CompanyRole role; } @Inheritance( strategy = InheritanceType. SINGLE_TABLE ) @DiscriminatorColumn( name="CATG", discriminatorType=DiscriminatorType.

STRING ) @Table( name = "Role" ) public Role { } @DiscriminatorValue( "CMPY_ROLE" ) public CompanyRole extends Role { private Company company } @Table( name = "COMPANY" ) Public Company { }.

Ok, I kind of followed your advice, thanks! I am now inserting a ROLE with already existing PERSON and COMPANY. This is ok, as both do and can exist without a ROLE relationship.

I configured two @OneToMany mappings in both the PERSON and COMPANY classes plus two @ManyToOne mappings in the ROLE class. I am not too sure about the data integrity so far, but it works as desired. Definitely interesting aspects using inheritance and cascading for these kind of situations.

Thanks again! – Wolfram Apr 24 '09 at 15:45.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions