- This topic has 8 replies, 4 voices, and was last updated 18 years ago by Giorgos Maravelias.
-
AuthorPosts
-
Eugen31MemberHi all again!
I am very new in hibernate and java, and i would appreciate some help or example that someone have.
I have a simple many-to-many association! Like Person and Equipment and we create a Person_Equipment table with two PKs like PersonID and EquipmentID.
How can i create the mapping file for this situation?
And the java class? How am i create this?!?!?Thanks,
Eugen Lechner
Haris PecoMemberEugene,
Select your tables in Db explorer, right clikc and call ‘Create Hibernate mapping’ – MyEclipse will make mapping and POJO for you
If you have problem further, send us your database type, version, Eclipse and MyEclipse version and your schema script (DDL with PK and FK)Best
Eugen31MemberHi,
I use PostgreSQL 8.1, Eclipse SDK 3.1.2 and MyEclipse 4.1.1.
DDL:
CREATE TABLE person (
id int8 CONSTRAINT PK_person_id PRIMARY KEY,
firstname varchar(50),
surname varchar(50)
)
WITHOUT OIDSCREATE TABLE equipment (
id int8 CONSTRAINT PK_equipment_id PRIMARY KEY,
title varchar(50),
description varchar(500)
)
WITHOUT OIDSCREATE TABLE person_equipment (
person_id int8,
equipment_id int8,
CONSTRAINT FK_person_id FOREIGN KEY (person_id) REFERENCES person (id),
CONSTRAINT FK_equipment_id FOREIGN KEY (equipment_id) REFERENCES equipment (id)
)
WITHOUT OIDSThe MyEclipse Hibernate tool creates 3 mapping files for person, equipment and person_equipment and 3 POJO-Classes. I need only two POJO classes with association HashSets between person and equipment.
Haris PecoMemberEugen,
I understand, but it’s hard that MyEclipse decide when you want many-to-many and we don’t support this.
If you want many-to-many mapping you have to change it manual
For your example you can remove PersonEquipment* (POJO and mapping) and change Person.hbm.xml to :<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Mapping file autogenerated by MyEclipse - Hibernate Tools --> <hibernate-mapping> <class name="Person" table="person" schema="public"> <id name="id" type="long"> <column name="id" /> <generator class="increment" /> </id> <property name="firstname" type="string"> <column name="firstname" length="50" /> </property> <property name="surname" type="string"> <column name="surname" length="50" /> </property> <set name="personEquipments" table="person_equipment" > <key> <column name="person_id" /> </key> <many-to-many class="Equipment" column="equipment_id" /> </set> </class> </hibernate-mapping>
I don’t sure if we have add features for many-to-many mappings
Best
Eugen31MemberThanks.
Can MyEclipse make POJO from mapping file with many-to-many association?
Eugene
Eugen31Member@support-snpe wrote:
Eugen,
I don’t sure if we have add features for many-to-many mappings
Best
I think the missing support of many-to-many association would be the first reason, why one did not become to use this tools for development in a company.
Haris PecoMemberCan MyEclipse make POJO from mapping file with many-to-many association?
yes.version 4.1.1 can do it
I think the missing support of many-to-many association would be the first reason, why one did not become to use this tools for development in a company.
ok.I think that it can be cool features, but what you think how MyEclipse can decide what is many-to-many
– tables with composite PK and all columns in PK are FK ? or how ?Thanks
gavin9Member@support-snpe wrote:
ok.I think that it can be cool features, but what you think how MyEclipse can decide what is many-to-many
– tables with composite PK and all columns in PK are FK ? or how ?Thanks
My suggestion is to make an option in the dialog, simple check box “Weak Entity” would be good where the IDE can determine the relationships from FK or even let the user map FK to tables via drop down boxes.
Regards
Giorgos MaraveliasMember+1 i have the same problem on my projects and i have to make the right changes manualy 🙂
-
AuthorPosts