• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

1-to-1 Hibernate Mapping Problem

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm creating a 1-to-1 association with Hibernate using unique foreign key associations. My two objects are User and Login.

But I encountered the following errors:

[java] net.sf.hibernate.MappingException: An association from the table USER refers to an unmapped class: com.finport.user.Login
[java] at net.sf.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:687)
[java] at net.sf.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:671)
[java] at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:789)
[java] at CreateTest.main(CreateTest.java:11)
[java] Exception in thread "main"
[java] Java Result: 1


The following are excerpts from both classes mapping files:

User.hbm.xml
=========================
<many-to-one
name="login"
class="com.finport.user.Login"
cascade="all"
outer-join="auto"
update="true"
insert="true"
access="property"
column="LOGINID"
unique="true"
/>

Login.hbm.xml
=========================
<one-to-one
name="user"
class="com.finport.user.User"
cascade="none"
outer-join="auto"
constrained="false"
property-ref="login"
/>


Does anyone have any idea what went wrong? Thanks in advance for your help.
 
Matthew Anderson
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just to add on, here's the code which causes the error:

Configuration config = new Configuration();
config.addClass(User.class);

SessionFactory sessionFactory = config.buildSessionFactory();
Session session = sessionFactory.openSession();
Transaction tx = null;

try {
Login login = new Login();
login.setLoginName("abc");
login.setPassword("password");

tx = session.beginTransaction();

User user = new User();
user.setFirstName("Ryuroni");
user.setLastName("Kenshin");
user.setEmail("Email");

user.setLogin(login);

session.save(user);

tx.commit();
....
....
 
Matthew Anderson
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How careless of me. I've forgotten to add this in:

config.addClass(Login.class);

Please ignore my previous posts.
My apologies.
 
reply
    Bookmark Topic Watch Topic
  • New Topic