-->
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.  [ 4 posts ] 
Author Message
 Post subject: how to i write a mapping file for this?
PostPosted: Mon Apr 10, 2006 6:54 am 
Newbie

Joined: Sat Mar 18, 2006 1:27 am
Posts: 15
suppose i have a table in my database which has such fields:

email (primary key)
password
familyname
givenname


and i have the persistent model

set and getEmail();
set and getPassword();
set and getFamilyname();
set and getGivenname();


how do i write the mapping file for this?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 10, 2006 8:56 am 
Beginner
Beginner

Joined: Wed Apr 05, 2006 3:19 pm
Posts: 43
Does this work?

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>
   <class name="OBJECT" table="database_table">
      <composite-id>
              <key-property name="email"/>
      </composite-id>
           <property name="password" />
              <property name="familyname" />
              <property name="givenname" />
       </class>
</hibernate-mapping>


Maybe this link might be useful: http://www.hibernate.org/hib_docs/v3/re ... ompositeid

I don't know if the composite-id can achief what you want, but you could certainly give it a try.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 11, 2006 6:08 am 
Beginner
Beginner

Joined: Mon May 02, 2005 6:17 pm
Posts: 41
How can you make a composite id from just one column?
Mapping you need is simplest possible and it's already well documented in ref doc. I would change email into unique key and primary key into some surrogate.

_________________
www.globalresearch.ca


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 11, 2006 3:44 pm 
Newbie

Joined: Mon Apr 10, 2006 2:58 pm
Posts: 8
I'm not sure why "Laurens" suggested a composite key, but you can try the following mapping file:

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>

    <class name="your.class.name" table="database_table">
        <id name="email" column="email" >
            <generator class="assigned" />
        </id>

        <property name="password" type="string" column="password" not-null="true" />
        <property name="familyname" type="string" column="familyname" not-null="true" />
        <property name="givenname" type="string" column="givenname" not-null="true" />
    </class>

</hibernate-mapping>


The above will use an assigned primary key. Remove the "not-null="true"" if the columsn can be null


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