-->
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: Problem in running one to many
PostPosted: Sun Aug 08, 2010 11:33 pm 
Newbie

Joined: Fri Jul 30, 2010 2:02 pm
Posts: 6
Hi,

I am facing the following issue while running one to many relationship.

Basically my code includes,
1. COURSE table and STUDENT table.
2. COURSE will be the master table containing different course names having CNO as Course Number as primary key.
3. STUDENT table contains SNO, SNAME and CNO as Student Number, Student Name and Course Number under which student is under going.
4. Following is the piece of Code.

StudentOneToMany POJO

Code:
public class StudentOneToMany {
      private Long studentNo;
      private String studentName;
               getters & setters ; 
}


Course POJO

Code:
public class Course {
   private long courseNo;
   private String courseName;
   private StudentOneToMany[] studentOneToManyArray;
           getters & setters;


Student.hbm.xml
Code:
<class name="edu.model.StudentOneToMany" table="STUDENTONETOMANY">
    <id name="studentNo" column="STUDENTNO">   
         <generator class="sequence" />
    </id>
    <property name="studentName" column="SNAME"/>
   
  </class>


Course.hbm.xml
Code:
<class name="edu.model.Course" table="COURSE">
    <id name="courseNo" column="CNO">   
         <generator class="sequence" />
    </id>
    <property name="courseName" column="CNAME"/>
   
    <array name="studentOneToManyArray">
     <key column="CNO"/>
     <list-index column="idx" />
     <one-to-many class="edu.model.StudentOneToMany" />
     </array>
  </class>


Hibernateconfig.xml
Code:
  <session-factory>
       
       <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
       <property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:SURESH</property>
       <property name="hibernate.connection.username">scott</property>
       <property name="hibernate.connection.password">tiger</property>
       <property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
       <property name="hibernate.show_sql">true</property>
       <property name="hibernate.hbm2ddl.auto">update</property>
       <property name="hibernate.use_sql_comments">true</property>
       <mapping resource="edu/mapping/Student.hbm.xml" />
       <mapping resource="edu/mapping/StudentXtra.hbm.xml" />
       <mapping resource="edu/mapping/Employee.hbm.xml" />
       <mapping resource="edu/mapping/StudentOneToMany.hbm.xml" />
       <mapping resource="edu/mapping/Course.hbm.xml" />
  </session-factory>

Please note these two tables are not present under database
Below is the Main Program

Code:
public static void main(String args[]){
      Session session = SessionUtil.currentSession();
      Transaction transaction = session.beginTransaction();
      StudentOneToMany studentOne = new StudentOneToMany();
      StudentOneToMany studentTwo = new StudentOneToMany();
      studentOne.setStudentName("abcd");
      studentTwo.setStudentName("efgh");
      
      StudentOneToMany[] studentOneToManyArray = new StudentOneToMany[] {studentOne, studentTwo};
      
      Course course = new Course();
      course.setCourseName("MCA");
      course.setStudentOneToManyArray(studentOneToManyArray);
      session.save(studentOneToManyArray);
      session.save(course);
      transaction.commit();
   }


I am getting the following exception and tables are being created but data is not getting inserted into the table, please help me out

Code:
[color=#FF0000]log4j:WARN No appenders could be found for logger (edu.util.SessionUtil).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.hibernate.MappingException: Unknown entity: [Ledu.model.StudentOneToMany;
   at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:628)
   at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1366)
   at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:121)
   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:563)
   at org.hibernate.impl.SessionImpl.save(SessionImpl.java:551)
   at org.hibernate.impl.SessionImpl.save(SessionImpl.java:547)
   at edu.main.OneToManyTest.main(OneToManyTest.java:24)[/color]


Top
 Profile  
 
 Post subject: Re: Problem in running one to many
PostPosted: Mon Aug 09, 2010 8:41 am 
Regular
Regular

Joined: Fri Aug 06, 2010 1:49 am
Posts: 102
Location: shynate26@gmail.com
This seems to be a problem in configuration file. Trying having pojo & hbm in same package . Get back with your results.

_________________

Cheers!
Shynate
mailto:shynate26@gmail.com
www.CSSCORP.com


Top
 Profile  
 
 Post subject: Re: Problem in running one to many
PostPosted: Tue Aug 10, 2010 10:38 pm 
Newbie

Joined: Fri Jul 30, 2010 2:02 pm
Posts: 6
In that case, table won't get created under database right? For me table is getting created under database, but not able to insert data into it.


Top
 Profile  
 
 Post subject: Re: Problem in running one to many
PostPosted: Wed Aug 11, 2010 12:02 am 
Regular
Regular

Joined: Fri Aug 06, 2010 1:49 am
Posts: 102
Location: shynate26@gmail.com
Tables got created because you have specified hbm2ddl.auto=update. What ever the changes you make in the mapping files its get reflected. But it clearly gives you error message unknown entity. So the mapping file not able to locate your entity file.

_________________

Cheers!
Shynate
mailto:shynate26@gmail.com
www.CSSCORP.com


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.