I'm trying to do many-to-many mapping, but have a problem with a code below. Tables created with this code looks fine, foreign keys are added properly. The problem occurs when I'm trying to create related objects and save them to db. After lunching app I have one row in table KURS, one row in table KATEGORIE, but the third table - KURSY_KATEGORIE is empty :(
Table1:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 2012-11-08 11:48:42 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="model.Kurs" table="KURS" node="kurs">
<id name="id" type="long">
<column name="ID_KURSU" />
<generator class="native" />
</id>
...
<set cascade="save-update" name="kategorie" inverse="true" lazy="true" table="KURSY_KATEGORIE">
<key foreign-key="FK_KATEGORIE_KURSY">
<column name="ID_KURSU" />
</key>
<many-to-many class="model.Kategoria" column="ID_KATEGORI"/>
</set>
</class>
</hibernate-mapping>
Table2:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 2012-11-08 11:48:42 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="model.Kategoria" table="KATEGORIA" node="kategoria">
<id name="id" type="long">
<column name="ID_KATEGORI" />
<generator class="native" />
</id>
...
<set cascade="save-update" name="kursy" table="KURSY_KATEGORIE" inverse="true" lazy="true">
<key foreign-key="FK_KURSY_KATEGORIE">
<column name="ID_KATEGORI" />
</key>
<many-to-many class="model.Kurs" column="ID_KURSU"/>
</set>
</class>
</hibernate-mapping>
And .java file:
Session session = SESSION_FACTORY.openSession();
Transaction tx = session.beginTransaction();
GregorianCalendar Data_rozp = new GregorianCalendar();
Kategoria cat1 = new Kategoria("Kategoria1");
Set<Kategoria> kategorie = new HashSet<Kategoria>(3);
kategorie.add(cat1);
Kurs k1 = new Kurs(Data_rozp, "kurs1", 100);
Set<Kurs> kursy = new HashSet<Kurs>(1);
kursy.add(k1);
cat1.setKursy(kursy);
k1.setKategorie(kategorie);
session.save(cat1);
session.save(k1);
tx.commit();
session.close();
Try changing:
<set cascade="save-update" name="kursy" table="KURSY_KATEGORIE" inverse="true" lazy="true">
To:
<set cascade="save-update" name="kursy" table="KURSY_KATEGORIE" lazy="true">
And:
<set cascade="save-update" name="kategorie" inverse="true" lazy="true" table="KURSY_KATEGORIE">
To:
<set name="kategorie" inverse="true" lazy="true" table="KURSY_KATEGORIE">
I'm surprised that hibernate does not throw an exception for invalid configuration (both ends can't be set as inverse - one must be the owner)
Related
I want to create the following tables with the necessary associations accordingly:
However, it seems that I have miyed up something because when Hibernate creates the tables multiple foreign keys are created as shown below:
INFO: HHH10001501: Connection obtained from JdbcConnectionAccess
[org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess#5e5595f3]
for (non-JTA) DDL execution was not in auto-commit mode; the
Connection 'local transaction' will be committed and the Connection
will be set into auto-commit mode.
Hibernate: create table APP.ITEMS (ITEM_ID integer generated by
default as identity, NAME varchar(100), NET_PRICE integer, VAT_RATE
integer, CATEGORY_ID integer not null, primary key (ITEM_ID))
Hibernate: create table APP.LIMIT (LIMIT_ID integer not null,
LIMIT_VALUE integer, primary key (LIMIT_ID))
Hibernate: create table APP.PARTNER (PARTNER_ID integer generated by
default as identity, PARTNER_NAME varchar(100), primary key
(PARTNER_ID))
Hibernate: create table APP.TRANSACTIONS (TRANSACTIONS_ID integer
generated by default as identity, FLOW integer not null, NET_PRICE
integer, ITEM_ID integer not null, advicenote integer, ADVICENOTE_ID
integer not null, primary key (TRANSACTIONS_ID))
Hibernate: alter table APP.TRANSACTIONS add constraint
UK_r7btjtpy72nugbhuia8y0xnk6 unique (ITEM_ID)
Hibernate: alter table APP.ADVICENOTE add constraint
FK4n4r6ej5i983gk8fqj20jl899 foreign key (partner) references
APP.PARTNER
Hibernate: alter table APP.ADVICENOTE add constraint
FKr96drd4j6pds8vocvsstcd2a2 foreign key (PARTNER_ID) references
APP.PARTNER
Hibernate: alter table APP.ITEMS add constraint
FKbbkng91eiiqu522okqq0nq7pm foreign key (CATEGORY_ID) references
APP.CATEGORIES
Hibernate: alter table APP.TRANSACTIONS add constraint
FK13kk35nfl3iff7f2cs8er8w0s foreign key (advicenote) references
APP.ADVICENOTE
Hibernate: alter table APP.TRANSACTIONS add constraint
FK8ilbnqyk8lemxj0yvbqm3p7tt foreign key (ITEM_ID) references APP.ITEMS
Hibernate: alter table APP.TRANSACTIONS add constraint
FKqrbn7tojjjkjyusy98a300btp foreign key (ADVICENOTE_ID) references
APP.ADVICENOTE
Hibernate: select categories0_.NAME as col_0_0_ from APP.CATEGORIES
categories0_
Hibernate: select items0_.ITEM_ID as ITEM_ID1_2_, items0_.NAME as
NAME2_2_, items0_.NET_PRICE as NET_PRIC3_2_, items0_.VAT_RATE as
VAT_RATE4_2_, items0_.CATEGORY_ID as CATEGORY5_2_ from APP.ITEMS
items0_
Hibernate: select items0_.ITEM_ID as ITEM_ID1_2_, items0_.NAME as
NAME2_2_, items0_.NET_PRICE as NET_PRIC3_2_, items0_.VAT_RATE as
VAT_RATE4_2_, items0_.CATEGORY_ID as CATEGORY5_2_ from APP.ITEMS
items0_
Hibernate: select categories0_.NAME as col_0_0_ from APP.CATEGORIES
categories0_
Hibernate: select items0_.ITEM_ID as ITEM_ID1_2_, items0_.NAME as
NAME2_2_, items0_.NET_PRICE as NET_PRIC3_2_, items0_.VAT_RATE as
VAT_RATE4_2_, items0_.CATEGORY_ID as CATEGORY5_2_ from APP.ITEMS
items0_
Is this normal behaviour or am I missing something?
Here are my XML mappings:
Advicenote.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated Feb 9, 2019, 3:57:52 PM by Hibernate Tools 4.3.1 -->
<hibernate-mapping>
<class name="classes.Advicenote" table="ADVICENOTE" schema="APP" optimistic-lock="version">
<id name="advicenoteId" type="int" column="ADVICENOTE_ID">
<generator class="native" />
</id>
<property name="advicedate" type="date" column="ADVICE_DATE" length="10" />
<property name="inOrOut" type="java.lang.Short" column="IN_OR_OUT" />
<many-to-one
name="partner" class="classes.Partner"/>
<set name="transactions" table="TRANSACTIONS" inverse="false" cascade="all" lazy="true" fetch="select">
<key column="ADVICENOTE_ID" not-null="true"/>
<one-to-many class="classes.Transactions"/>
</set>
</class>
</hibernate-mapping>
Categories.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="classes.Categories" table="CATEGORIES" schema="APP" optimistic-lock="version">
<id name="categoryId" type="int">
<column name="CATEGORY_ID" />
<generator class="native" />
</id>
<property name="name" type="string">
<column name="NAME" length="100" />
</property>
<set name="items" table="ITEMS" inverse="true" cascade="all" lazy="false" fetch="select">
<key>
<column name="CATEGORY_ID" not-null="true" />
</key>
<one-to-many class="classes.Items" />
</set>
</class>
</hibernate-mapping>
Items.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="classes.Items" table="ITEMS" schema="APP" optimistic-lock="version">
<id name="itemId" type="int" column="ITEM_ID">
<generator class="native" />
</id>
<property name="name" type="string" column="NAME" length="100"/>
<property name="netPrice" type="java.lang.Integer" column="NET_PRICE"/>
<property name="vatRate" type="java.lang.Integer" column="VAT_RATE"/>
<many-to-one name="category" class="classes.Categories" fetch="select" column="CATEGORY_ID" not-null="true" lazy="false"/>
</class>
</hibernate-mapping>
Limit.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="classes.Limit" table="LIMIT" schema="APP" optimistic-lock="version">
<id name="limitId" type="java.lang.Integer" column="LIMIT_ID">
<generator class="assigned"/>
</id>
<property name="value" type="int" column="LIMIT_VALUE" length="1000"/>
</class>
</hibernate-mapping>
Partner.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="classes.Partner" table="PARTNER" schema="APP">
<id name="partnerId" type="int">
<column name="PARTNER_ID"/>
<generator class="native"/>
</id>
<property name="partnerName" type="string" column="PARTNER_NAME" length="100"/>
<set name="advicenotes" table="ADVICENOTE" inverse="false" cascade="all" lazy="true" fetch="select">
<key column="PARTNER_ID" not-null="true"/>
<one-to-many class="classes.Advicenote" />
</set>
</class>
</hibernate-mapping>
Transactions.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="classes.Transactions" table="TRANSACTIONS" schema="APP" optimistic-lock="version">
<id name="transactionsId" type="int" column="TRANSACTIONS_ID">
<generator class="native" />
</id>
<property name="flow" type="int" column="FLOW" not-null="true" />
<property name="netPrice" type="java.lang.Integer" column="NET_PRICE" />
<many-to-one name="advicenote" class="classes.Advicenote"/>
<many-to-one name="item" class="classes.Items" fetch="select" cascade="save-update" column="ITEM_ID" unique="true" not-null="true"/>
</class>
</hibernate-mapping>
An AdviceNote mapping JoinColumn is missing
<many-to-one name="partner" class="classes.Partner">
<join-column name="PARTNER_ID"/>
</many-to-one>
I have two entities and two value objects - Employee, Card, Employee Number & Card Number. The relationship between Employee and Card is a one-to-many. I create an instance of Employee and an instance of Card like so and save them to the database...
EmployeeRepositoryHibernate employeeRepository = new EmployeeRepositoryHibernate();
employeeRepository.setSessionFactory();
employeeRepository.getSession().beginTransaction();
EmployeeNumber employeeNumber = new EmployeeNumber("MNO");
Location location = new Location("Room 1");
CardNumber cardNumber = new CardNumber("1");
Employee employee = new Employee(employeeNumber, location);
Card card = new Card(cardNumber, "1111", employee);
employeeRepository.getSession().save(employee);
employeeRepository.getSession().save(card);
employeeRepository.getSession().getTransaction().commit();
employeeRepository.getSession().close();
Except, it won't save, the following error message is shown... I can save an employee, but the message is thrown when I try to save a related card... the mysql database isn't relational yet.. both tables are separate...
Problem fixed: required related tables.
Caused by: java.sql.SQLException: Field 'employeeNumber' doesn't have a default value
Here are the two Hibernate XML mapping files for Card and Employee...
Card
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-access="field">
<class name="model.Card" table="Card">
<id name="CardID" type="long">
<column name="CardID" />
<generator class="identity" />
</id>
<component name="cardNumber" unique="true">
<property name="number" column="cardNumber"/>
</component>
<many-to-one name="employee" class="model.Employee" fetch="select">
<column name="EmpID" not-null="true"></column>
</many-to-one>
<property name="PIN" column="PIN"/>
</class>
</hibernate-mapping>
Employee
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-access="field">
<class name="model.Employee" table="employee">
<id name="EmpID" column="EmpID">
<generator class="org.hibernate.id.IdentityGenerator"/>
</id>
<component name="employeeNumber" class="model.EmployeeNumber" >
<property name="number" column="employeeNumber" type="string"/>
</component>
<component name="location">
<property name="location" column="Location" type="string"/>
</component>
<set name="cards" inverse="true" cascade="all">
<key>
<column name="EmpID" not-null="true"></column>
</key>
<one-to-many class="model.Card"/>
</set>
</class>
</hibernate-mapping>
One of these might help:
Add a default value to the column employeeNumber
ALTER TABLE 'table_name' ALTER 'employeeNumber' SET DEFAULT NULL
Use auto increment if you are using employeeNumber as a primary key.
Supply value to the employeeNumber column during insertion.
Its being a while since I don't do Hibernate and I wanted to do some simple example the other day but when I needed to do a one to many relationship the many side doesn't get inserted into the database. This is how the database looked like.
This are my mappings for the person:
Java
public class ORMPerson implements Serializable {
private Long uniqueId;
private String firstName;
private String secondName;
private Long fkAddress;
hbm
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="orm">
<class name="orm.ORMPerson" table="PERSON">
<id name="uniqueId" column="UNIQUE_ID">
<generator class="increment"/>
</id>
<property name="firstName" column="FIRST_NAME"/>
<property name="secondName" column="SECOND_NAME"/>
<many-to-one name="fkAddress" class="orm.ORMPerson" column="FK_ADDRESS" cascade="all" not-null="false" />
</class>
</hibernate-mapping>
This are the mappings for Address:
Java
public class ORMAddress implements Serializable {
private Long uniqueId;
private String firstLine;
private String secondLine;
private String postcode;
private Set<ORMPerson> ormPersons;
hbm
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="orm">
<class name="orm.ORMAddress" table="ADDRESS">
<id name="uniqueId" column="UNIQUE_ID">
<generator class="increment"/>
</id>
<property name="firstLine" column="FIRST_LINE"/>
<property name="secondLine" column="SECOND_LINE"/>
<property name="postcode" column="POSTCODE"/>
<set name="ormPersons" table="ADDRESS" inverse="true" fetch="select" cascade="save-update">
<key>
<column name="UNIQUE_ID" not-null="true" />
</key>
<one-to-many class="ORMPerson"/>
</set>
</class>
</hibernate-mapping>
And this is the client code that I use to insert an address with multiple persons:
ORMAddress ormAddress = new ORMAddress();
ormAddress.setFirstLine(address.getFirstLine());
ormAddress.setSecondLine(address.getSecondLine());
ormAddress.setPostcode(address.getPostcode());
ormAddress.setOrmPersons(ormPersons);
session.save(ormAddress);
session.getTransaction().commit();
If I try to call the session.save() method with ormPersons, I will see the data being added to the database, but the foreign kew will have no value. I think this is because I just have a not-null="false" in Person but this is not a solution, I think all should be inserted automatically by just calling once the save method.
The reason is hidden in the inverse="true" mapping. This is saying to Hibernate:
when you persist collection - let that job on its items. These items must be aware of their parent.
But as we can see above, the ormPersons are not provided with back reference to ormAddress.
...
// after that line we have to do more
ormAddress.setOrmPersons(ormPersons);
// we have to assign back reference
for(ORMPerson ormPerson: ormPersons) {
ormPerson.setOrmAddress(ormAddress);
}
and also we would need ORMAddress reference inside of the ORMPerson - not as LONG
public class ORMPerson implements Serializable {
...
private ORMAddress ormAddress;
hbm
<class name="orm.ORMPerson" table="PERSON">
....
<many-to-one name="ormAddress" class="orm.ORMPerson"
column="FK_ADDRESS" cascade="all" not-null="false" />
</class>
And finally, many-to-one and one-to-many must use the same column
hbm of Address (FK_ADDRESS):
<class name="orm.ORMAddress" table="ADDRESS">
...
<set name="ormPersons" table="ADDRESS" inverse="true"
fetch="select" cascade="save-update">
<key>
//<column name="UNIQUE_ID" not-null="true" />
<column name="FK_ADDRESS" not-null="true" /> // the parent id
</key>
<one-to-many class="ORMPerson"/>
</set>
Check the doc for an example:
23.2. Bidirectional one-to-many
I was using a Set but now due to a widget restriction, I need to use a list.a
a sample of my mapping file using A SET and a List are as follows. Can someone help me to place the list index. I am getting some confusion.
**Attribute Mapping File using Set**
?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Dec 16, 2010 5:25:09 AM by Hibernate Tools 3.4.0.Beta1 -->
<hibernate-mapping>
<class name="h.Attribute" table="ATTRIBUTE">
<id name="AttributeId" type="long">
<column name="ATTRIBUTEID" />
<generator class="native" />
</id>
<property name="AttributeName" type="java.lang.String">
<column name="ATTRIBUTENAME" />
</property>
<set name="Options" table="ATTRIBUTEOPTION" inverse="false" cascade="all" lazy="true">
<key>
<column name="ATTRIBUTEID" />
</key>
<one-to-many class="h.AttributeOption" />
</set>
</class>
</hibernate-mapping>
**Category Mapping File using Set**
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Dec 16, 2010 8:37:02 AM by Hibernate Tools 3.4.0.Beta1 -->
<hibernate-mapping>
<class name="h.Category" table="CATEGORY">
<id name="CategoryId" type="long">
<column name="CATEGORYID" />
<generator class="native" />
</id>
<property name="CategoryName" type="java.lang.String">
<column name="CATEGORYNAME" />
</property>
<many-to-one name="ParentCategory" class="h.Category">
<column name="PARENT_CATEGORY_ID" />
</many-to-one>
<set name="SubCategory" lazy="true" cascade="all-delete-orphan" inverse="true">
<key>
<column name="PARENT_CATEGORY_ID" />
</key>
<one-to-many class="h.Category" />
</set>
<set name="AllAttributes" table="ATTRIBUTE" inverse="false" lazy="true" cascade="all">
<key>
<column name="CATEGORYID" />
</key>
<one-to-many class="h.Attribute" />
</set>
</class>
</hibernate-mapping>
Category Mapping File using list without the list index
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Dec 17, 2010 2:10:50 AM by Hibernate Tools 3.4.0.Beta1 -->
<hibernate-mapping>
<class name="h.Category" table="CATEGORY">
<id name="CategoryId" type="long">
<column name="CATEGORYID" />
<generator class="assigned" />
</id>
<property name="CategoryName" type="java.lang.String">
<column name="CATEGORYNAME" />
</property>
<many-to-one name="ParentCategory" class="h.Category" fetch="join">
<column name="PARENTCATEGORY" />
</many-to-one>
<list name="SubCategory" inverse="false" table="CATEGORY" lazy="true">
<key>
<column name="CATEGORYID" />
</key>
<list-index></list-index>
<one-to-many class="h.Category" />
</list>
<list name="AllAttributes" inverse="false" table="ATTRIBUTE" lazy="true" cascade="all">
<key>
<column name="CATEGORYID" />
</key>
<list-index></list-index>
<one-to-many class="h.Attribute" />
</list>
</class>
</hibernate-mapping>
Attribute Mapping File using list with not list index
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Dec 17, 2010 2:10:50 AM by Hibernate Tools 3.4.0.Beta1 -->
<hibernate-mapping>
<class name="h.Attribute" table="ATTRIBUTE">
<id name="AttributeId" type="long">
<column name="ATTRIBUTEID" />
<generator class="assigned" />
</id>
<property name="AttributeName" type="java.lang.String">
<column name="ATTRIBUTENAME" />
</property>
<list name="Options" inverse="false" table="ATTRIBUTEOPTION" lazy="true" cascade="all">
<key>
<column name="ATTRIBUTEID" />
</key>
<list-index></list-index>
<one-to-many class="h.AttributeOption" />
</list>
</class>
</hibernate-mapping>
Read Hibernate Reference: 6.2.3. Indexed collections
For Example:
<list name="whatEver">
<key column="whatEver_fk"/>
<index column="idx"/>
<one-to-many class="WhatEver"/>
</list>
The Hibernate 3.3 reference says "The index of an array or list is always of type integer...", and also "If your table does not have an index column, and you still wish to use list as the property type, you can map the property as a Hibernate <bag>."
A example of bag:
<bag name="options" table="ATTRIBUTEOPTION" order-by="column_name asc|desc" inverse="true" lazy="true" fetch="select">
<key column="ATTRIBUTEID" />
<one-to-many class="h.AttributeOption" />
</bag>
I think you should give "index" property in POJO for which you are creating one-to-many relation
<list name="whatEver">
<key column="whatEver_fk"/>
<index column="idx"/>
<one-to-many class="WhatEver_Class"/>
</list>
In above example , "WhatEver_Class" POJO should have a index property , and it's hbm file should have below property tag.
<property name="index" type="long" insert="false" update="false">
<column name="idx" />
</property>
I have two tables: a "Module" table and a "StaffModule" table. I want to display a list of modules by which staff are present on the staffmodule mapping table.
I've tried
from Module join Staffmodule sm with ID = sm.MID
with no luck, I get the following error
Path Expected for join!
However, I thought I had the correct join too allow this, but this is obviously not the case. Can any one help?
StaffModule HBM
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Apr 26, 2010 9:50:23 AM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class name="Hibernate.Staffmodule" schema="WALK" table="STAFFMODULE">
<composite-id class="Hibernate.StaffmoduleId" name="id">
<key-many-to-one name="mid" class="Hibernate.Module">
<column name="MID"/>
</key-many-to-one>
<key-property name="staffid" type="int">
<column name="STAFFID"/>
</key-property>
</composite-id>
</class>
</hibernate-mapping>
and Module.HBM
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Apr 26, 2010 9:50:23 AM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class name="Hibernate.Module" schema="WALK" table="MODULE">
<id name="id" type="int">
<column name="ID"/>
<generator class="assigned"/>
</id>
<property name="modulename" type="string">
<column length="50" name="MODULENAME"/>
</property>
<property name="teacherid" type="int">
<column name="TEACHERID" not-null="true"/>
</property>
</class>