Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
3.x
Mapping documents:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="xxx.pojo.PostponeDateLimit" table="POSTPONE_DATE_LIMIT">
<composite-id class="xxx.pojo.PostponeDateLimitKey" mapped="true">
<key-property name="postponeDate" type="calendar_date" column="TARGET_DATE"/>
<key-property name="controlCode" column="CONTROL_CODE"/>
</composite-id>
<property name="maxCount" column="MAX_COUNT"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Full stack trace of any exception that occurs:Name and version of the database you are using:The generated SQL (show_sql=true):Debug level Hibernate log excerpt:Code:
233528 DEBUG org.hibernate.loader.Loader | total objects hydrated: 1
233528 DEBUG org.hibernate.engine.TwoPhaseLoad | resolving associations for [xxx.pojo.PostponeDateLimit#component[postponeDate,controlCode]{control
Code=050, postponeDate=17 November 2008}]
233528 DEBUG org.hibernate.engine.TwoPhaseLoad | done materializing entity [com.
xxx.pojo.PostponeDateLimit#component[postponeDate,controlCode]{controlC
ode=050, postponeDate=17 November 2008}]
233528 DEBUG org.hibernate.engine.StatefulPersistenceContext | initializing non-
lazy collections
233528 DEBUG org.hibernate.loader.Loader | done entity load
233528 DEBUG org.hibernate.jdbc.JDBCContext | after autocommit
233528 DEBUG org.hibernate.jdbc.ConnectionManager | transaction completed on session with on_close connection release mode; be sure to close the session to rele
ase JDBC resources!
233528 DEBUG org.hibernate.impl.SessionImpl | after transaction completion
233528 DEBUG org.hibernate.event.def.AbstractFlushingEventListener | flushing se
ssion
233528 DEBUG org.hibernate.event.def.AbstractFlushingEventListener | processing
flush-time cascades
233528 DEBUG org.hibernate.event.def.AbstractFlushingEventListener | dirty check
ing collections
233528 DEBUG org.hibernate.event.def.AbstractFlushingEventListener | Flushing en
tities and processing referenced collections
233528 DEBUG org.hibernate.impl.SessionImpl | closing session
233528 DEBUG org.hibernate.jdbc.ConnectionManager | performing cleanup
233528 DEBUG org.hibernate.jdbc.ConnectionManager | releasing JDBC connection [
(open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
233528 DEBUG org.hibernate.jdbc.JDBCContext | after transaction completion
233528 DEBUG org.hibernate.jdbc.ConnectionManager | transaction completed on ses
sion with on_close connection release mode; be sure to close the session to rele
ase JDBC resources!
233528 DEBUG org.hibernate.impl.SessionImpl | after transaction completion
233528 WARN com.acs.gs.eJuror.web.struts.services.impl.BaselineEJurorExceptionH
andler | execute()
233544 ERROR com.acs.gs.eJuror.web.struts.services.impl.BaselineEJurorExceptionH
andler | Exception Encountered in Web Layer : identifier of an instance of xxx.pojo.PostponeDateLimit was altered from 'PostponeDate:11/17/2008 0:0
0 AM|Control Code:050' to 'PostponeDate:11/17/2008 0:00 AM|Control Code:050'; nested exception is org.hibernate.HibernateException: identifier of an instance of
xxx.pojo.PostponeDateLimit was altered from 'PostponeDate:11/17/20
08 0:00 AM|Control Code:050' to 'PostponeDate:11/17/2008 0:00 AM|Control Code:05
0'
org.springframework.orm.hibernate3.HibernateSystemException: identifier of an in
stance of xxx.pojo.PostponeDateLimit was altered from 'PostponeDate
:11/17/2008 0:00 AM|Control Code:050' to 'PostponeDate:11/17/2008 0:00 AM|Contro
l Code:050'; nested exception is org.hibernate.HibernateException: identifier of
an instance of xxx.pojo.PostponeDateLimit was altered from 'Postpo
neDate:11/17/2008 0:00 AM|Control Code:050' to 'PostponeDate:11/17/2008 0:00 AM|
Control Code:050'
Caused by:
org.hibernate.HibernateException: identifier of an instance of xxx.pojo.PostponeDateLimit was altered from 'PostponeDate:11/17/2008 0:00 AM|Control
Code:050' to 'PostponeDate:11/17/2008 0:00 AM|Control Code:050'
at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(Defau
ltFlushEntityEventListener.java:58)
at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(Def
aultFlushEntityEventListener.java:157)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity
(DefaultFlushEntityEventListener.java:113)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(A
bstractFlushingEventListener.java:196)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverything
ToExecutions(AbstractFlushingEventListener.java:76)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlus
hEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary
(HibernateAccessor.java:390)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(Hibernat
eTemplate.java:373)
at org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTem
plate.java:464)
at org.springframework.orm.hibernate3.HibernateTemplate.get(HibernateTem
plate.java:458)
at xxx.dao.impl.PostponeDateLimitDAOImpl.getLimitForDate(Po
stponeDateLimitDAOImpl.java:29)
Code where the error is happening (using spring):
Code:
public long getLimitForDate(Calendar date, String divCode) {
PostponeDateLimitKey key = new PostponeDateLimitKey(date, divCode);
PostponeDateLimit limit =(PostponeDateLimit) getHibernateTemplate().get(PostponeDateLimit.class, key);
if(limit==null){
return -1;
}
return limit.getMaxCount();
}
The POJOs:
Code:
public class PostponeDateLimit extends PostponeDateLimitKey {
private static final long serialVersionUID = 1L;
private long maxCount;
/**
* no-arg constructor
*/
public PostponeDateLimit() {
super();
}
/**
* copy constructor
*/
public PostponeDateLimit(PostponeDateLimit postponeDateLimit) {
super(postponeDateLimit);
ReflectionUtil.copyJavaBean(postponeDateLimit, this);
}
/**
* fully-qualified constructor
* @param postponeDate the postpone date requested
* @param control_code the control code for that date
* @param maxCount the limit specified
*/
public PostponeDateLimit(Calendar postponeDate, String control_code, long maxCount) {
super(postponeDate, control_code);
setMaxCount(maxCount);
}
/* (non-Javadoc)
* @see xxx.pojo.PostponeDateLimitKey#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (obj instanceof PostponeDateLimit) {
PostponeDateLimit limit = (PostponeDateLimit) obj;
boolean ret = super.equals(limit);
if(ret){
ret = getMaxCount() == limit.getMaxCount();
}
return ret;
}
return false;
}
/* (non-Javadoc)
* @see xxx.pojo.PostponeDateLimitKey#hashCode()
*/
@Override
public int hashCode() {
return toString().hashCode();
}
/* (non-Javadoc)
* @see xxx.pojo.PostponeDateLimitKey#toString()
*/
@Override
public String toString() {
StringBuilder sb = new StringBuilder(super.toString());
sb.append("|Max count:");
sb.append(getMaxCount());
return sb.toString();
}
/**
* @return the maxCount
*/
public long getMaxCount() {
return maxCount;
}
/**
* @param maxCount the maxCount to set
*/
public void setMaxCount(long maxCount) {
this.maxCount = maxCount;
}
Code:
private static final long serialVersionUID = 1L;
private String controlCode;
private Calendar postponeDate;
/**
* no-arg constructor
*/
public PostponeDateLimitKey() {
super();
}
/**
* copy constructor
*/
public PostponeDateLimitKey(Calendar date, String controlCode) {
this();
setControlCode(controlCode);
setPostponeDate(date);
}
/**
* copy constructor
*/
public PostponeDateLimitKey(PostponeDateLimitKey key) {
this();
setControlCode(key.getControlCode());
setPostponeDate(key.getPostponeDate());
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (obj instanceof PostponeDateLimitKey) {
PostponeDateLimitKey limitKey = (PostponeDateLimitKey) obj;
return toString().equals(limitKey.toString());
}
return false;
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
return toString().hashCode();
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
CalendarFormatter cf = CalendarFormatter.getFormatter();
StringBuilder sb = new StringBuilder();
sb.append("'PostponeDate:");
sb.append(cf.getShortDate(getPostponeDate()));
sb.append(" ");
sb.append(cf.getShortTime((getPostponeDate())));
sb.append("|Control Code:");
sb.append(getControlCode().trim());
sb.append("'");
return sb.toString();
}
/**
* @return the postponeDate
*/
public Calendar getPostponeDate() {
return postponeDate;
}
/**
* @param postponeDate the postponeDate to set
*/
public void setPostponeDate(Calendar postponeDate) {
this.postponeDate = postponeDate;
}
/**
* based on the configuration paramter, this is how we're counting the limit. e.g., by court location
* or division code
* @return the divisionCode
*/
public String getControlCode() {
return controlCode;
}
/**
* based on the configuration paramter, this is how we're counting the limit. e.g., by court location
* or division code
* @param controlCode the divisionCode to set
*/
public void setControlCode(String controlCode) {
this.controlCode = controlCode;
}
}
I find it interesting that the dump says it's comparing PostponeDateLimit objects, but the toString() method is from PostponeDateLimitKey.
Ideas?
Thanks.