File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes hibernate mapping problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "hibernate mapping problem" Watch "hibernate mapping problem" New topic
Author

hibernate mapping problem

Shusha Li
Greenhorn

Joined: Mar 16, 2010
Posts: 4
Hi, All,

I am new to hibernate, please help. I want to map different tables to one class like this
Tables:
1)Loan:
-loanID
-currentBalance

2)Address :
- addressID
- street
- citystatezip

3)Property:
- propertyID;
- addressID;
- loanID;

I create single POJO class AccountView which contains fields from ALL tables.
public class AccountView{
long loanID;
double currentBalance;
Address address;
}
i also have a class Address in a different folder
public class Address{
long addressID;
String street;
String citystatezip;
}

I did my hibernate mapping for AccountView as following:
<hibernate-mapping>
<class name="com.myaccount.AccountView" table="Loan">
<cache usage="read-only"/>
<id name="loanID" type="long" unsaved-value="-1">
<column name="loanID" sql-type="long" not-null="true"/>
<generator class="assigned"/>
</id>
<property column="currentBalance" name="currentBalance" not-null="false" type="double"/>
<set name="address" table="PROPERTY" cascade="all">
<key column="loanID" />
<many-to-many column="addressID" class="com.myprofile.Address" />
</set>
</class>
</hibernate-mapping>

But it gives me errors....

Please suggest me how to do hibernate mapping(Mapping *.hbm.xml file) in this case.

Thanks in Advance.
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

Howdy Greenhorn!

It's so good to have you here at JavaRanch. I was just wondering if you could just take a quick gander at your JavaRanch private messages?

Thanks so much!

http://www.javaranch.com/name.jsp

-Cameron McKenzie
Shusha Li
Greenhorn

Joined: Mar 16, 2010
Posts: 4
changed... Thank you!
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

Well, let's start with the error. What's the message you're getting when you try to run your code?
Shashank Acharya
Greenhorn

Joined: Mar 20, 2010
Posts: 21

i suggest you to make different mapping(.hbm.xml) files for each table that would be helpful when you are trying to alter your tables in future. Even though I have two tables in project I used different mapping files.
 
wood burning stoves
 
subject: hibernate mapping problem
 
Similar Threads
Is Nested Join possible, mapping a POJO to multiple tables.
Hibernate, User and Address with association table between
org.hibernate.MappingException: table refers to an unmapped class
One to Many Mapping : org.hibernate.MappingException: Association references unmapped class
Foreign key must have same number of columns