-->
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.  [ 6 posts ] 
Author Message
 Post subject: saveOrUpdateCopy doesnt work
PostPosted: Tue May 11, 2004 8:29 am 
Newbie

Joined: Tue May 11, 2004 5:51 am
Posts: 4
Hi,

I am using saveOrUpdateCopy() for saving Company object. The company object contains contact object. How ever when i try to save the company object using saveOrUpdateCopy() i get the following error:

"exception setting property value with CGILIB (set hibernate.cgilib.use_reflection_optimizer=false for more info) getter property com.Contact.?"

I tried to set the hibernate.cgilib.use_reflection_optimizer to false in hibernate.cfg.xml however i still cannot see any other information.

Please help...


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 11, 2004 5:11 pm 
Regular
Regular

Joined: Thu Jan 29, 2004 10:34 am
Posts: 52
Location: Austin, TX
you are going to have to post the code for the Company and Contact objects along with their hibernate mapping xmls.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 12, 2004 2:04 am 
Newbie

Joined: Tue May 11, 2004 5:51 am
Posts: 4
here are hbm files for Company & Contact objects.

<!-- Contact Object -->
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping package="com.manheim.mafs.usemafs.ps.vo">

<class name="com.manheim.mafs.usemafs.ps.vo.Contact" table="um_contact_details" select-before-update="false">
<id name="muuId" type="long" column="muuId" >
<generator class="assigned">
</generator>

</id>
<version name="oca" column="oca" type="integer" unsaved-value="null"></version>

<property name="email" column="email"/>
<property name="fax" column="fax"/>
<property name="firstName" column="first_name"/>
<property name="hideFlags" column="hide_flags"/>
<property name="lastName" column="last_name"/>
<property name="phone" column="phone"/>
<property name="preferredContact" column="pref_contact"/>
</class>

</hibernate-mapping>

<!-- Company Object -->
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping package="com.manheim.mafs.usemafs.ps.vo">

<class name="com.manheim.mafs.usemafs.ps.vo.Company" table="um_company" select-before-update="false">
<id name="muuId" type="long" column="muuId" >
<generator class="assigned"/>
<!-- To be assigned by the application before save is called -->
</id>
<version name="oca" column="oca" type="integer" unsaved-value="null"></version>
<property name="companyName" column="company_name" />
<property name="companyDesc" column="company_desc"/>
<property name="companyURL" column="company_url"/>
<property name="createdBy" column="created_by"/>
<property name="lastUpdatedTime" column="last_updated_time"/>
<property name="modifiedBy" column="modified_by"/>

<!-- many-to-many relationship -->
<set name="categoryList" table="um_cat_comp_rel">
<key column="comp_id"/>
<many-to-many class="com.manheim.mafs.usemafs.ps.vo.Category" column="cat_id"/>
</set>
<!-- one to one relation ship -->
<one-to-one name="contactObject" class="com.manheim.mafs.usemafs.ps.vo.Contact" outer-join="auto" cascade="all"/>

<!-- one-to-many relationship -->
<set name="addresses" inverse="true" cascade="all" lazy="true">
<key column="comp_id"/>
<one-to-many class="com.manheim.mafs.usemafs.ps.vo.Address" />
</set>

<!-- one to one relation ship -->
<one-to-one class="com.manheim.mafs.usemafs.ps.vo.User" name="userObject" outer-join="auto" cascade="all"/>
</class>

<query name="validateCompanyName">
from com.manheim.mafs.usemafs.ps.vo.Company as company where upper(company.companyName) = :1
</query>

</hibernate-mapping>
<!-- parsed in 0ms -->

And their corresponding POJO objects are as follows:
public class Contact extends BaseObject {

private String firstName;
private String lastName;
private String preferredContact;
private String phone;
private String fax;
private String email;
private String hideFlags;
private int oca;


public Contact() {
super();
}

/**
* @return String
*/
public String getEmail() {
return email;
}

/**
* @return String
*/
public String getFax() {
return fax;
}

/**
* @return String
*/
public String getFirstName() {
return firstName;
}

/**
* @return String
*/
public String getHideFlags() {
return hideFlags;
}

/**
* @return String
*/
public String getLastName() {
return lastName;
}



/**
* @return String
*/
public String getPhone() {
return phone;
}

/**
* @return String
*/
public String getPreferredContact() {
return preferredContact;
}

/**
* @param string
*/
public void setEmail(String string) {
email = string;
}

/**
* @param string
*/
public void setFax(String string) {
fax = string;
}

/**
* @param string
*/
public void setFirstName(String string) {
firstName = string;
}

/**
* @param strings
*/
public void setHideFlags(String string) {
hideFlags = string;
}

/**
* @param string
*/
public void setLastName(String string) {
lastName = string;
}



/**
* @param string
*/
public void setPhone(String string) {
phone = string;
}

/**
* @param string
*/
public void setPreferredContact(String string) {
preferredContact = string;
}

/**
* @return
*/
public int getOca() {
return oca;
}

/**
* @param i
*/
public void setOca(int i) {
oca = i;
}

/**
* toString() for getting the contact details in string format.
*
* @return String contact details
*/
public String toString() {
return "Contact Details: First Name: " + getFirstName() + ";Last Name: " + getLastName()+
";Preferred Contact: " + getPreferredContact() + ";Phone: " + getPhone() +
";Fax: " + getFax() + ";Email: " + getEmail()+";Hide Flags: "+getHideFlags()+
";OCA: "+getOca()+";MUUId: "+getMuuId();
}


}


public class Company extends BaseObject {

private String companyName;
private String companyURL;
private String companyDesc;
private Set addresses;
private Set categoryList;
private java.lang.String createdBy;
private java.lang.String modifiedBy;
public java.sql.Timestamp lastUpdatedTime;
private User userObject;
private Contact contactObject;
private String[] categoryString;
private int oca;
private Address primaryAddress;
private Address secondaryAddress;

public Company() {
// needed for beanutils to copy properties
setUserObject(new User());
setContactObject(new Contact());
HashSet hSet = new HashSet();
hSet.add(new Address());
hSet.add(new Address());
primaryAddress = new Address();
secondaryAddress = new Address();
setAddresses(hSet);
setCategoryList(new HashSet());
}

/**
* @return String
*/
public String getCompanyDesc() {
return companyDesc;
}

/**
* @return String
*/
public String getCompanyName() {
return companyName;
}

/**
* @return String
*/
public String getCompanyURL() {
return companyURL;
}

/**
* @return Contact
*/
public Contact getContactObject() {
return contactObject;
}

/**
* @param string
*/
public void setCompanyDesc(String string) {
companyDesc = string;
}

/**
* @param string
*/
public void setCompanyName(String string) {
companyName = string;
}

/**
* @param string
*/
public void setCompanyURL(String string) {
companyURL = string;
}

/**
* @param contact
*/
public void setContactObject(Contact contact) {
this.contactObject = contact;
}

/**
* @return
*/
public java.lang.String getCreatedBy() {
return createdBy;
}

/**
* @return
*/
public java.sql.Timestamp getLastUpdatedTime() {
return lastUpdatedTime;
}

/**
* @return
*/
public java.lang.String getModifiedBy() {
return modifiedBy;
}

/**
* @return
*/
public User getUserObject() {
return userObject;
}

/**
* @param string
*/
public void setCreatedBy(java.lang.String string) {
createdBy = string;
}

/**
* @param timestamp
*/
public void setLastUpdatedTime(java.sql.Timestamp timestamp) {
lastUpdatedTime = timestamp;
}



/**
* @param string
*/
public void setModifiedBy(java.lang.String string) {
modifiedBy = string;
}

/**
* @param user
*/
public void setUserObject(User user) {
userObject = user;
}

/**
* @return
*/
public Set getAddresses() {
return addresses;
}

/**
* @return
*/
public Set getCategoryList() {
return categoryList;
}

/**
* @param set
*/
public void setAddresses(Set set) {
addresses = set;
Iterator addrItr = addresses.iterator();
Address addr = null;
while (addrItr.hasNext()) {
addr = (Address)addrItr.next();
if (addr.isPrimary()) {
primaryAddress = addr;
}
else {
secondaryAddress = addr;
}
}

}

/**
* @param set
*/
public void setCategoryList(Set set) {
categoryList = set;
}

/**
* @return
*/
public String[] getCategoryString() {
return categoryString;
}

/**
* @param strings
*/
public void setCategoryString(String[] strings) {
categoryString = strings;
}

/**
* @return
*/
public int getOca() {
return oca;
}

/**
* @param i
*/
public void setOca(int i) {
oca = i;
}

public Address getPrimaryAddress() {
return primaryAddress;
}
/**
* @return
*/
public Address getSecondaryAddress() {
return secondaryAddress;
}

}
[/b]


Top
 Profile  
 
 Post subject: More information on the saveOrUpdateCopy() problem
PostPosted: Wed May 12, 2004 8:47 am 
Newbie

Joined: Tue May 11, 2004 5:51 am
Posts: 4
I would like to add further information on the problem which i am facing for saveOrUpdateCopy() method. Now when i was finally able to set the hibernate.cgilib.use_reflection_optimizer=false i am getting the following error:

java.lang.NullPointerException
at java.lang.reflect.Method.invoke(Native Method)
at net.sf.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:96)
at net.sf.hibernate.persister.AbstractEntityPersister.getPropertyValues(AbstractEntityPersister.java:246)
at net.sf.hibernate.impl.SessionImpl.doCopy(SessionImpl.java:3990)
at net.sf.hibernate.impl.SessionImpl.saveOrUpdateCopy(SessionImpl.java:3938)
at com.manheim.mafs.usemafs.ps.dao.HibernateCategoryDAO.addCategory(HibernateCategoryDAO.java:68)
at com.manheim.mafs.usemafs.ps.bo.CategoryBO.addCategory(CategoryBO.java:65)
at com.manheim.mafs.usemafs.ps.command.AddCategoryCommand.performExecute(AddCategoryCommand.java:53)
at com.manheim.mafs.usemafs.framework.BaseCommand.execute(BaseCommand.java:92)
at com.manheim.mafs.usemafs.ps.action.AddCategoryAction.execute(AddCategoryAction.java:99)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:211)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:309)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:336)
at com.evermind._cub._pod(.:521)
at com.evermind._cub._bmc(.:177)
at com.evermind._ax._ltc(.:666)
at com.evermind._ax._uab(.:191)
at com.evermind._bf.run(.:62)

I'd really appreciate if some one could help me on this problem. I have been working on this for past 3 days !!!!!!

Thanx in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 12, 2004 5:44 pm 
Regular
Regular

Joined: Thu Jan 29, 2004 10:34 am
Posts: 52
Location: Austin, TX
first i assume that you have a default constructor for Company (i.e. in the BaseObject).

the mappings looked fine to me but the message
Quote:
getter property com.Contact.?"

seems to indicate an erroneouse method name during the doCopy() in the session. it's hard to debug this from here so setup breakpoints in the follwing methods in the hibernate source
Code:
AbstractEntityPersister.setPropertyValues
AbstractEntityPersister.getPropertyValues

and step through it during the save. you should see one of the getter methods being set to null.

let us know what you find.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 13, 2004 12:51 am 
Newbie

Joined: Tue May 11, 2004 5:51 am
Posts: 4
Thanx a lot for your reply Ravi.

I finally figured out that the null pointer was because i was trying to use saveOrUpdateCopy() while trying to add a new record to the database.
So i have changed the code to use saveOrUpdate for adding a new row and saveOrUpdateCopy() for modifying the existing row in the database. However i am facing another problem here. One of my UI components are structured as follows:
I have a Company object. And company has primary address and secondary address. Now the user may prefer not to enter the secondary address when he/she is adding the company. In that case no data for secondary address goes to the database. This works fine. However when the user tries to add the secondary address while editing the company, this time i use saveOrUpdateCopy() and it gives the same null pointer since it doesnt find the secondary address in the database.

Please let me know what can be done here.

Thanx in advance.


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