-->
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.  [ 10 posts ] 
Author Message
 Post subject: One-To-Many Relationship using MySQL Issue
PostPosted: Wed Nov 26, 2008 6:43 am 
Beginner
Beginner

Joined: Wed Nov 19, 2008 6:39 am
Posts: 44
Location: Mumbai, India
On MySQL, I have a table Dept and Emp with following structures,

CREATE TABLE `test`.`dept` (
`deptid` int(10) unsigned NOT NULL,
`dname` varchar(45) NOT NULL,
PRIMARY KEY (`deptid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;



CREATE TABLE `test`.`emp` (
`deptid` int(10) unsigned NOT NULL,
`empname` varchar(45) NOT NULL,
`empsalary` int(10) unsigned NOT NULL,
`empid` int(10) unsigned NOT NULL auto_increment,
PRIMARY KEY (`empid`),
CONSTRAINT `deptid` FOREIGN KEY (`deptid`) REFERENCES `dept` (`deptid`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=latin1;

while running i am getting folowing error
Error Message:

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Inserting Record
Hibernate: insert into dept (dname) values (?)
three****org.hibernate.exception.GenericJDBCException: could not insert: [com.muru.pojo.Dept]
Hibernate: select max(empid) from Emp
four****org.hibernate.AssertionFailure: null id in com.muru.pojo.Dept entry (don't flush the Session after an exception occurs)
Murugesan one-to-many Record has scuccessfully
org.hibernate.AssertionFailure: null id in com.muru.pojo.Dept entry (don't flush the Session after an exception occurs)
at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:78)
at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:187)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:143)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:219)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:49)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
at com.muru.pojo.DeptTest.main(DeptTest.java:61)
Exception in thread "main"

Codes:
hibernate.cfg.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.bytecode.use_reflection_optimizer">false</property>
        <property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
        <property name="hibernate.connection.password">XYZ</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost/test</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="hibernate.show_sql">true</property>
        <mapping resource="News.hbm.xml" />
        <mapping resource="Emp.hbm.xml" />
        <mapping resource="Dept.hbm.xml" />
       
    </session-factory>
</hibernate-configuration>


Emp.java
Code:
package com.muru.pojo;

public class Emp {
   private Long empid;
   private String empname;
   private int empsalary;
   
   public Emp(String name,int salary){
      setEmpname(name);
      setEmpsalary(salary);
   }
   public Long getEmpid() {
      return empid;
   }
   public void setEmpid(Long empid) {
      this.empid = empid;
   }
   public String getEmpname() {
      return empname;
   }
   public void setEmpname(String empname) {
      this.empname = empname;
   }
   public int getEmpsalary() {
      return empsalary;
   }
   public void setEmpsalary(int empsalary) {
      this.empsalary = empsalary;
   }
   
   
   
}


Emp.hbm.xml
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="com.muru.pojo">
  <class name="Emp">
     <id name="empid" column="empid">
        <generator class="increment"></generator>
     </id>
     <property name="empname" column="empname" generated="never"></property>
     <property name="empsalary" column="empsalary" type="int" generated="never"></property>
   
  </class>
</hibernate-mapping>


Dept.java
Code:
package com.muru.pojo;

import java.util.HashSet;
import java.util.Set;

public class Dept {
   private Long id;
   private String dname;
   private Set emps;
   
   public String getDname() {
      return dname;
   }
   public void setDname(String dname) {
      this.dname = dname;
   }
   public Set getEmps() {
      return emps;
   }
   public void setEmps(Set emps) {
      this.emps = emps;
   }
   public Long getId() {
      return id;
   }
   public void setId(Long id) {
      this.id = id;
   }
}



Dept.hbm.xml
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="com.muru.pojo">
   <class  name="Dept" table="dept">
      <id name="id" column="deptid" type="java.lang.Long">
         <generator class="native"></generator>
      </id>
      
      <property name="dname" column="dname" generated="never"></property>
      
      <set name="emps" cascade="all-delete-orphan">
         <key column="deptid" />
         <one-to-many class="Emp" />
      </set>
   
   </class>
</hibernate-mapping>


DeptTest.java
Code:
package com.muru.pojo;

import java.util.HashSet;
import java.util.Set;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

public class DeptTest {
   public static void main(String arg[]) {
      Session session = null;

      try {
         // This step will read hibernate.cfg.xml and prepare hibernate for
         // use
         SessionFactory sessionFactory = new

         Configuration().configure().buildSessionFactory();
         session = sessionFactory.openSession();
         // Create new instance of Contact and set values in it by reading
         // them from form object
         System.out.println("Inserting Record");
         Transaction tr = session.beginTransaction();

         // this is for one-to-many unidirectional code
         Dept test = new Dept();
         test.setId(new Long("5"));
         test.setDname("Computer Work");

         Set emp = new HashSet();
         try {
            emp.add(new Emp("PM", 1000));
         } catch (Exception e) {
            System.out.println("one****" + e);
         }
         try {
            emp.add(new Emp("MP", 1111));
         } catch (Exception e) {
            System.out.println("two****" + e);
         }
         try {
            // session.save(emp);
            test.setEmps(emp);
            session.save(test);
         } catch (Exception e) {
            System.out.println("three****" + e);
         }
         try {

            tr.commit();
         } catch (Exception e) {
            System.out.println("four****" + e);
         }
         System.out
               .println("Murugesan one-to-many Record has scuccessfully");
      } catch (Exception e) {
         System.out.println(e);
      } finally {
         session.flush();
         session.close();
      }

   }
}


I have tried with all class of generator(<generator class="..">) in dept.hbm.xml. But i won't get any solution.

Please help me on this.

Thanks in Advance.

Murugesan.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 26, 2008 8:10 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Something goes wrong at the line that calls session.save(test);. In the 'catch' clause that follows can you add a line that prints the complete stack trace?

Code:
...
} catch (Exception e) {
  //System.out.println("three****" + e);
   e.printStackTrace();
}


This will give you a lot more info.

Anyway, there is a discrepancy between the mapping and the database. In Dept.hbm.xml you have <generator class="native">, but the 'deptid' column in the database is not an AUTO_INCREMENT column.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 28, 2008 1:38 am 
Beginner
Beginner

Joined: Wed Nov 19, 2008 6:39 am
Posts: 44
Location: Mumbai, India
Thx for your reply.

I have small doubt. I don't have AUTO_INCREMENT in Dept table. It is Primary key and it is not a auto increment. Shall we define this kind of field in <generator class="native"> or any other way for it?

As per your advice i had put e.printStackeTrace() at three catch block and got following error.

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Inserting Record
Hibernate: insert into dept (dname) values (?)
org.hibernate.exception.GenericJDBCException: could not insert: [com.muru.pojo.Dept]
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:64)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2186)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2666)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:71)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:321)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:562)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:550)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:546)
at com.muru.pojo.DeptTest.main(DeptTest.java:46)
Caused by: java.sql.SQLException: Field 'deptid' doesn't have a default value
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:946)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3283)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1332)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1604)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1519)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1504)
at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:94)
at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:57)
... 16 more
Hibernate: select max(empid) from Emp
four****org.hibernate.AssertionFailure: null id in com.muru.pojo.Dept entry (don't flush the Session after an exception occurs)
Murugesan one-to-many Record has scuccessfully
org.hibernate.AssertionFailure: null id in com.muru.pojo.Dept entry (don't flush the Session after an exception occurs)
at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:78)
at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:187)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:143)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:219)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:49)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
at com.muru.pojo.DeptTest.main(DeptTest.java:62)
Exception in thread "main"

Pls help me.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 28, 2008 3:34 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Quote:
I don't have AUTO_INCREMENT in Dept table. It is Primary key and it is not a auto increment. Shall we define this kind of field in <generator class="native"> or any other way for it?


Since you are using MySQL a <generator class="native"> needs the primary key column to be an AUTO_INCREMENT column. If you don't want to use AUTO_INCREMENT on that column, you should use a different generator. Which one depends on your needs. You can find more information here:

http://www.hibernate.org/hib_docs/v3/re ... -generator


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 28, 2008 3:45 am 
Beginner
Beginner

Joined: Wed Nov 19, 2008 6:39 am
Posts: 44
Location: Mumbai, India
I have changed the Dept table structure into Auto_Increment and modified the Dept.hbm.xml. So now both tables are having Auto increment. And tried to run. I got JDBC batch exception while running. I modifed the hfg.xml with <property name="hibernate.jdbc.batch_size">0</property>,so that that batch error was gone. But i got new error.

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Inserting Record
Hibernate: select max(deptid) from dept
Hibernate: select max(empid) from Emp
id value===5
Hibernate: insert into dept (dname, deptid) values (?, ?)
Hibernate: insert into Emp (empname, empsalary, empid) values (?, ?, ?)
four****org.hibernate.exception.GenericJDBCException: could not insert: [com.muru.pojo.Emp]
five****org.hibernate.exception.GenericJDBCException: could not insert: [com.muru.pojo.Emp]
org.hibernate.exception.GenericJDBCException: could not insert: [com.muru.pojo.Emp]
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2295)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2688)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:79)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:365)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
at com.muru.pojo.DeptTest.main(DeptTest.java:54)
Caused by: java.sql.SQLException: Field 'deptid' doesn't have a default value
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:946)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3283)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1332)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1604)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1519)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1504)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:46)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2275)
... 11 more
Murugesan one-to-many Record has scuccessfully

DeptTest.java
Code:
package com.muru.pojo;

import java.util.HashSet;
import java.util.Set;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

public class DeptTest {
   public static void main(String arg[]) {
      Session session = null;

      try {
         // This step will read hibernate.cfg.xml and prepare hibernate for
         // use
         SessionFactory sessionFactory = new

         Configuration().configure().buildSessionFactory();
         session = sessionFactory.openSession();
         // Create new instance of Contact and set values in it by reading
         // them from form object
         System.out.println("Inserting Record");
         Transaction tr = session.beginTransaction();

         // this is for one-to-many unidirectional code
         Dept test = new Dept();
         //test.setId(new Long("5"));
         test.setDname("Computer Work");
         
         Set emp = new HashSet();
         try {
            emp.add(new Emp("PM", 1000));
         } catch (Exception e) {
            System.out.println("one****" + e);
         }
         try {
            emp.add(new Emp("MP", 1111));
         } catch (Exception e) {
            System.out.println("two****" + e);
         }
         try {
            // session.save(emp);
            test.setEmps(emp);
            session.save(test);
            System.out.println("id value==="+test.getId());
                        
         } catch (Exception e) {
            //System.out.println("three****" + e);
            e.printStackTrace();
         }
         try {

            tr.commit();
         } catch (Exception e) {
            System.out.println("four****" + e);
            //e.printStackTrace();
            if (tr != null) {
               tr.rollback();
               System.out.println("five****" + e);
               e.printStackTrace();
            }
         }
         System.out.println("Murugesan one-to-many Record has scuccessfully");
      } catch (Exception e) {
         System.out.println(e);
      } finally {
         //session.flush();
         session.close();
      }

   }
}


Pls help me.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 28, 2008 4:05 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Quote:
Hibernate: select max(deptid) from dept
Hibernate: select max(empid) from Emp


Are you no longer using <generator class="native">? It seems more like you are using <generator class="increment"> which is not the same thing. The latter will do the ID generation in Java and doesn't need the column to be AUTO_INCREMENT. But this is not what is causing the error.

Your table 'emp' has a column 'deptid', but your class 'Emp' doesn't define a property for this column. The column is defined in the <set> in 'Dept.hbm-xml', but since it is not really part of the Emp class the insert is a two-step process. First the Emp is inserted with only the properties defined in the Emp.hbm.xml mapping. Then, the link between Dept and Emp is created with an UPDATE statement that set a value for the 'deptid' column. Your code fails in the first step because the 'deptid' doesn't allow null. The proper solution is to map the relation as a bi-directional association. You need to add a <many-to-one> in Emp.hbm.xml and make the <set> in Dept.hbm.xml inverse. This is a classical parent/child relation and you can read more here: http://www.hibernate.org/hib_docs/v3/re ... child.html


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 28, 2008 4:29 am 
Beginner
Beginner

Joined: Wed Nov 19, 2008 6:39 am
Posts: 44
Location: Mumbai, India
i want to use One-to-many unidirectional relationship. My codes

Dept.hbm.xml
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="com.muru.pojo">
   <class  name="Dept" table="dept">
      <id name="id" column="deptid" type="java.lang.Long">
         <generator class="increment"></generator>
      </id>
      
      <!-- <composite-id>
         <key-property name="id" column="deptid"></key-property>
      </composite-id>-->
      
      <property name="dname" column="dname"></property>
      
      <set name="emps" cascade="all" >
         <key column="deptid" />
         <one-to-many class="Emp" />
      </set>
   
   </class>
</hibernate-mapping>


Emp.hbm.xml
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="com.muru.pojo">
  <class name="Emp">
     <id name="empid" column="empid">
        <generator class="increment"></generator>
     </id>
     <property name="empname" column="empname"></property>
     <property name="empsalary" column="empsalary" type="int" ></property>
     
   
  </class>
</hibernate-mapping>


I am new to Hibernate. Please help me. May be i asked very basic steps :)[/img]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 28, 2008 4:29 am 
Beginner
Beginner

Joined: Wed Nov 19, 2008 6:39 am
Posts: 44
Location: Mumbai, India
i want to use One-to-many unidirectional relationship. My codes

Dept.hbm.xml
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="com.muru.pojo">
   <class  name="Dept" table="dept">
      <id name="id" column="deptid" type="java.lang.Long">
         <generator class="increment"></generator>
      </id>
      
      <!-- <composite-id>
         <key-property name="id" column="deptid"></key-property>
      </composite-id>-->
      
      <property name="dname" column="dname"></property>
      
      <set name="emps" cascade="all" >
         <key column="deptid" />
         <one-to-many class="Emp" />
      </set>
   
   </class>
</hibernate-mapping>


Emp.hbm.xml
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="com.muru.pojo">
  <class name="Emp">
     <id name="empid" column="empid">
        <generator class="increment"></generator>
     </id>
     <property name="empname" column="empname"></property>
     <property name="empsalary" column="empsalary" type="int" ></property>
     
   
  </class>
</hibernate-mapping>


I am new to Hibernate. Please help me. May be i asked very basic steps :)[/img]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 28, 2008 4:40 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Quote:
i want to use One-to-many unidirectional relationship


Then you need to change the 'deptid' column in the 'emp' table to allow null values.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 28, 2008 4:47 am 
Beginner
Beginner

Joined: Wed Nov 19, 2008 6:39 am
Posts: 44
Location: Mumbai, India
Thx Lot. Problem was gone. And working as i expected. Visit me at http://www.murugesanpitchandi.com. Thx in advance.


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