-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: A component mapped by two different classes
PostPosted: Wed Sep 23, 2009 11:32 am 
Newbie

Joined: Wed Aug 12, 2009 10:45 am
Posts: 16
Assume I have three classes, User, CreditCard and Address. User has a collection of Address objects and CreditCard has a reference to an Address object. I am not supporting shared references, so I am not making Address an entity.

Code:
public class User {
   
   private long id;
   
   private String name;
   
   private Set<Address> homeAddresses=new HashSet<Address>();
   
   
   private CreditCard creditCard;
//the rest of the class

public class CreditCard {
   
   private long id;
   
   private String owner;
   
   private Address billingAddress;

//rest of class


public class Address {
   private String street;
   private String city;





Here are my mapping files:

Code:
<?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 Sep 23, 2009 10:20:59 AM by Hibernate Tools 3.2.5.Beta -->
<hibernate-mapping>
    <class name="user.CreditCard"  table="PAYMENTOPTION" >
        <id name="id" type="long">
            <column name="ID" />
            <generator class="native" />
        </id>
        <property name="owner" type="java.lang.String">
            <column name="OWNER" />
        </property>
       
       
        <join table="Addresses">
           <key column="ADDRESS_ID"></key>
           <component name="billingAddress" class="user.Address">
              <property name="city"></property>
               <property name="street"></property>
           </component>
        </join>
    </class>
</hibernate-mapping>


Code:
<?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 Sep 23, 2009 10:20:59 AM by Hibernate Tools 3.2.5.Beta -->
<hibernate-mapping>
    <class name="user.User"  table="USERS" >
        <id name="id" type="long">
            <column name="ID" />
            <generator class="native" />
        </id>
        <property name="name" type="java.lang.String">
            <column name="NAME" />
        </property>
        <set name="homeAddresses" inverse="false" lazy="true" table="ADDRESSES">
            <key>
                <column name="ADDRESS_ID" />
            </key>
           
            <composite-element class="user.Address">
              <property name="city"></property>
               <property name="street"></property>
            </composite-element>
        </set>
        <many-to-one name="payment" class="user.PaymentOption" fetch="select">
            <column name="PAYMENT_ID" />
        </many-to-one>
    </class>
</hibernate-mapping>



I am getting some kind of exception in the sessin factory creation. It tells me that User is un-mapped!
Any ideas? Thank you very much.
Kamal


Top
 Profile  
 
 Post subject: Re: A component mapped by two different classes
PostPosted: Wed Sep 23, 2009 12:34 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Sometimes it can be a case sensitive question. Make sure your class has the proper qualified name in the Java code, and you're not doing some incorrect import.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.