• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

hibernate mapping problem

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
author and cow tipper
Posts: 5000
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
changed... Thank you!
 
Cameron Wallace McKenzie
author and cow tipper
Posts: 5000
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, let's start with the error. What's the message you're getting when you try to run your code?
 
Greenhorn
Posts: 21
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
    Bookmark Topic Watch Topic
  • New Topic