-->
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.  [ 3 posts ] 
Author Message
 Post subject: problem while saving object
PostPosted: Mon Apr 16, 2007 8:34 am 
Newbie

Joined: Mon Apr 16, 2007 2:30 am
Posts: 8
Location: Lahore
hi, i got a problem while saving object, but the selection queries running fine. There is no exception throws but object is not persisted even console prints the next value for ID filed like

"11:15:21,656 INFO [Server] JBoss (MX MicroKernel) [4.0.5.GA (build: CVSTag=Bran
ch_4_0 date=200610162339)] Started in 29s:391ms
11:15:41,812 INFO [STDOUT] Hibernate: select max(cid) from companies
11:15:42,265 INFO [STDOUT] Hibernate: select companyimp0_.cid as cid0_, company
imp0_.company_name as company2_0_ from companies companyimp0_"


My code is


public class CompanyDAOImpl implements CompanyDAO {

SessionFactory sessionFactory;
Session session;
Transaction trans;
java.io.Serializable ser;

public CompanyDAOImpl() {
}

public void insert(CompanyImpl company){
try{
session = this.getCurrentSession();

trans = session.getTransaction();
trans.begin();
session.saveOrUpdate(company);

trans.commit();

java.util.List l= (java.util.List)session.createQuery("from com.springer.impl.CompanyImpl").list();
for(int i=0; i<l.size(); i++){
System.out.println(((CompanyImpl)l.get(i)).companyName);
}

} catch (Exception ex){
ex.printStackTrace();
trans.rollback();
} finally {
session.close();
}
}


Kindly send me comment about to resolve that problem.

thanks

_________________
Kashif Bashir

Mobex Limited
kashefbasher@gmail.com


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 16, 2007 9:20 am 
Regular
Regular

Joined: Fri May 12, 2006 4:05 am
Posts: 106
Hi,

what's the type of CompanyImpl's id-property?
Is there already an id-value set in the company-object that is passed to insert()?
And you should really post your class-mapping, cause there might be some bugs in there too....


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 16, 2007 9:57 am 
Newbie

Joined: Mon Apr 16, 2007 2:30 am
Posts: 8
Location: Lahore
hi,
thanks for reply, i am using auto-generated value in MySql Database.
my class mapping is
***************************
<hibernate-mapping>

<class name="com.springer.impl.CompanyImpl" table="companies" lazy="true">
<id name="id" column="cid">
<generator class="increment"/>
</id>
<property name="companyName" column="company_name" insert="true" update="true" />
</class>

</hibernate-mapping>

***************************
POJO is
***************************
public class CompanyImpl implements com.springer.Company {

public CompanyImpl() {
}

public String companyName;
public int id;

public String getCompanyName() {
return companyName;
}

public void setCompanyName(String companyName) {
this.companyName = companyName;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}
}
***************************

regards,

Kashif

_________________
Kashif Bashir

Mobex Limited
kashefbasher@gmail.com


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