Announcement Announcement Module
Collapse
No announcement yet.
database table mapping in hibernate-help plz Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    Originally posted by sheetal View Post
    is it possible to map one database table to several pojo?
    yes

    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

    Comment


    • #3
      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>

      Comment


      • #4
        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?

        Comment


        • #5
          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)*)".

          Comment


          • #6
            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)

            Comment


            • #7
              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>

              Comment


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

                Comment


                • #9
                  thaaaaaaaaaanks

                  Comment


                  • #10
                    thaaaaaanks, its working

                    Comment


                    • #11
                      You are welcome

                      Comment

                      Working...
                      X