Hi,
I am newbie here. I have 3 tables - User, Address, UserAddresss.
TablesUser table strucutreuserId integer (primary key)
userFirstname char
userLastName char
Address table structureuserAddressId integer (primary key)
Street char
city char
zip char
UserAddress table structure - composite key table
userId integer (primary key) - references User table
userAddressId integer (primary key) - references Address table
Composite Primary Key (userId + userAddressId)
Mapping filesUser.hbm.xmlCode:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="UserProfileObj" table="User">
<id name="uId" type="java.lang.Integer" column="userId">
<generator class="increment" />
</id>
<one-to-many name="userAddress" column="userId" unique="true" not-null="true" insert="false" update="false" />
<property name="uId">
<column name="userId" />
</property>
<property name="uFirstName">
<column name="userFirstname" />
</property>
<property name="uLastName">
<column name="userLastName" />
</property>
</class>
</hibernate-mapping>
UserAddress.hbm.xmlCode:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="UserAddressObj" table="UserAddress">
<composite-id>
<key-property name="uId" column="userId" />
<key-property name="uAddressId" column="userAddressId" />
</composite-id>
<many-to-one name="userId" column="userId" insert="false" update="false" not-null="true" />
</class>
</hibernate-mapping>
Address.hbm.xmlCode:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="AddressObj" table="Address">
<id name="uAddressId" type="java.lang.Integer" column="userAddressId">
<generator class="increment" />
</id>
<property name="uStreet">
<column name="Street" />
</property>
<property name="ucity">
<column name="city" />
</property>
<property name="uzip">
<column name="zip" />
</property>
</class>
</hibernate-mapping>
Java objectsCode:
public class UserProfileObj {
private Integer userId;
private String uFirstName;
private String uLastName;
private List userAddress;
getters/setters....
}
public class UserAddressObj {
public UserAddressObj() {
}
private Integer userId;
private Integer uAddressId;
getters/setters....
}
public class AddressObj {
public AddressObj() {
}
private Integer uAddressId;
private String ustreet;
private String ucity;
private String uzip;
getters/setters....
}
In this case, one User has one or many Addresses.
I am trying to apply Create/Read/Update/Delete (CRUD) operation using hibernate.
I used one-to-many mapping in parent mapping xml and many-to-one in child mapping xml, but no use.
I was getting class should have atleast one meta tag error.
Do I need three mapping files or two is enough? Can anyone fix this mapping files and/or java objects.
I am not sure where is the exact error?
Any help is greatly appreciated.
Thanks,
Sam