-->
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.  [ 5 posts ] 
Author Message
 Post subject: Need help mapping a property
PostPosted: Tue Aug 09, 2005 6:19 pm 
Newbie

Joined: Fri Jun 03, 2005 3:40 pm
Posts: 7
Hey, here´s my case:

TABLE PRODUCT
- PNUMBER (PK)
- NAME
- ...

TABLE PRODUCT_TYPE
- PNUMBER(PK/FK)
- TYPE(PK/FK)
- ...

TABLE TYPE
- TYPE(PK)
- DESCRIPTION
- ...


How can i map type into product? Is there a way? I do not have the TYPE info anywhere else in the system(it´s a legacy system...)! thanks!!!


Top
 Profile  
 
 Post subject: Re: Need help mapping a property
PostPosted: Tue Aug 09, 2005 7:04 pm 
Beginner
Beginner

Joined: Thu Mar 31, 2005 9:58 pm
Posts: 25
Location: Valparaiso
chinanihc2 wrote:
Hey, here´s my case:

TABLE PRODUCT
- PNUMBER (PK)
- NAME
- ...

TABLE PRODUCT_TYPE
- PNUMBER(PK/FK)
- TYPE(PK/FK)
- ...

TABLE TYPE
- TYPE(PK)
- DESCRIPTION
- ...


How can i map type into product? Is there a way? I do not have the TYPE info anywhere else in the system(it´s a legacy system...)! thanks!!!



Try a ManyToOne relationship from the product to the type

_________________
Daniel Casanueva R.

Jcode
Valparaiso, Chile


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 09, 2005 7:09 pm 
Beginner
Beginner

Joined: Thu Mar 31, 2005 9:58 pm
Posts: 25
Location: Valparaiso
with EJB3Annotations there will be something like this:

@Entity
public class Product{

//.......

@ManyToOne
@JoinColumn(nullable = false)
public Type getType() {
//.........
}

}

_________________
Daniel Casanueva R.

Jcode
Valparaiso, Chile


Top
 Profile  
 
 Post subject: Re: Need help mapping a property
PostPosted: Tue Aug 09, 2005 7:41 pm 
Beginner
Beginner

Joined: Thu Feb 17, 2005 9:20 pm
Posts: 36
Location: Vancouver, WA
chinanihc2 wrote:
Hey, here´s my case:

TABLE PRODUCT
- PNUMBER (PK)
- NAME
- ...

TABLE PRODUCT_TYPE
- PNUMBER(PK/FK)
- TYPE(PK/FK)
- ...

TABLE TYPE
- TYPE(PK)
- DESCRIPTION
- ...


How can i map type into product? Is there a way? I do not have the TYPE info anywhere else in the system(it´s a legacy system...)! thanks!!!



Here is your 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" >

<hibernate-mapping package="model">

    <class name="Product" table="PRODUCT">
        <id name="pnumber" column="pnumber" type="java.lang.Integer">
            <generator class="native"/>
        </id>

        <property name="name" column="NAME" type="java.lang.String" />
    </class>

    <class
   name="ProductType"
   table="PRODUCT_TYPE" >

        <id name="type" column="TYPE" type="java.lang.Integer">
            <generator class="native"/>
        </id>
   
        <many-to-one
           name="product"
           column="pnumber"
           class="product"
           not-null="true" />
      
   <joined-subclass
      name="Type"
      table="TYPE" >
       
             <key column="type" />
   </joined-subclass>
   
    </class>

</hibernate-mapping>



but you will be needed to change id generators to your DB ability
It should work

_________________
Vasyl Zhabko


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 09, 2005 7:45 pm 
Beginner
Beginner

Joined: Thu Feb 17, 2005 9:20 pm
Posts: 36
Location: Vancouver, WA
I forget to add DESCRIPTION to Type class :-)

_________________
Vasyl Zhabko


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.