Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: database table mapping in hibernate-help plz

  1. #1
    Join Date
    Jun 2007
    Posts
    18

    Default database table mapping in hibernate-help plz

    is it possible to map one database table to several pojo?
    & if i map 1 table to 1 class hierarchy then is it necessary that only the parent class should contain the attribute representing the primary key ?

  2. #2
    Join Date
    Jul 2005
    Posts
    5

    Default

    Quote Originally Posted by sheetal View Post
    is it possible to map one database table to several pojo?
    yes

    Quote Originally Posted by sheetal View Post
    & if i map 1 table to 1 class hierarchy then is it necessary that only the parent class should contain the attribute representing the primary key ?
    no

    hth

  3. #3
    Join Date
    Jun 2007
    Posts
    18

    Default

    plz tell me how?
    can i do it like :
    <class name="class1" table="table1">
    <property name="p1" column="p1"/>
    </class>

    <class name="class3" table="table1">
    <property name="p3" column="p3"/>
    </class>

    <class name="class2" table="table1">
    <property name="p2" column="p2"/>
    </class>

  4. #4
    Join Date
    Sep 2004
    Location
    London, UK
    Posts
    64

    Default

    Quote Originally Posted by sheetal View Post
    plz tell me how?
    can i do it like :
    <class name="class1" table="table1">
    ...
    yes. Do you have any problems with this?

  5. #5
    Join Date
    Jun 2007
    Posts
    18

    Question

    yeah.
    this is my db table :
    create table User(
    ComponentId numeric primary key not null,
    UniqueCode varchar(20) unique,
    VersionNumber varchar(20),
    CreationDate date,
    Status varchar(20),
    UserId varchar(20)unique,
    Name varchar(20),
    Email varchar(40),
    Password varchar(20),
    Description varchar(40)
    );
    and its my .hbm.xml
    <class name="com.vonair.nexus.core.BusinessEntity" table="User" >
    <property name="description" column="Description" />
    </class>
    <class name="com.vonair.nexus.core.PersistenceCapableDTO" table="User">
    <id name="componentId" column="ComponentId" >
    <generator class="increment" />
    </id>

    <property name="uniqueCode"column="UniqueCode" />
    <property name="versionNumber" column="VersionNumber" />
    <property name="creationDate" column="CreationDate" />
    <property name="status" column="Status" />
    </class>
    <class name="com.vonair.nexus.user.UserDTO"
    table="User">


    <property name="userId" column="UserId" />
    <property name="password" column="Password" />
    <property name="name" column="Name"/>
    <property name="email" column="Email" />
    </class>
    and here is the exception i'm getting:
    org.hibernate.InvalidMappingException: Could not parse mapping document
    Caused by: org.xml.sax.SAXParseException: The content of element type "class" must match "(meta*,subselect?,cache?,synchronize*,comment?,tu plizer*,(id|composite-id),discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|ar ray|primitive-array)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,resultset*,(query|sql-query)*)".

  6. #6
    Join Date
    Sep 2004
    Location
    London, UK
    Posts
    64

    Default

    Can you provide whole hbm.xml? I see at least one problem in provided xml:
    Code:
    <property name="uniqueCode"column="UniqueCode" />
    (There are no space between " and column)

  7. #7
    Join Date
    Jun 2007
    Posts
    18

    Default

    thank u for helping.
    here is the whole file:
    <?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="com.vonair.nexus.core.PersistenceCapableDTO" table="User">
    <id name="componentId" column="ComponentId" >
    <generator class="increment" />
    </id>

    <property name="uniqueCode" column="UniqueCode" />
    <property name="versionNumber" column="VersionNumber" />
    <property name="creationDate" column="CreationDate" />
    <property name="status" column="Status" />
    </class>
    <class name="com.vonair.nexus.user.UserDTO"
    table="User">


    <property name="userId" column="UserId" />
    <property name="name" column="Name"/>

    <property name="password" column="Password" />
    <property name="email" column="Email" />
    </class>
    <class name="com.vonair.nexus.core.BusinessEntity" table="User" >
    <property name="description" column="Description" />
    </class>

    </hibernate-mapping>

  8. #8
    Join Date
    Sep 2004
    Location
    London, UK
    Posts
    64

    Default

    UserDTO and BusinessEntity class configurations are not valid. They haven't id tag

  9. #9
    Join Date
    Jun 2007
    Posts
    18

    Default

    thaaaaaaaaaanks

  10. #10
    Join Date
    Jun 2007
    Posts
    18

    Default

    thaaaaaanks, its working

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •