Hi. I am currently working on a project using hibernate and have recently upgraded to use the hibernate 3.3.2.GA release. When compiling my j2ee project using maven there is some problems with one of my classfiles.
I suspect it has something to do with it extending the CompositeUserType hibernate class. I would really appreciate if anyone could give me a hint to how to solve this problem.
Code:
[exec] [wsejbdeploy] Invoking RMIC.
[exec] [wsejbdeploy] error: Class org.jaxen.FunctionContext not found.
[exec] [wsejbdeploy] error: Class org.dom4j.Document contains an invalid argument type in method createXPath.
[exec] [wsejbdeploy] error: Class org.hibernate.type.AbstractType contains an invalid argument type in method setToX
MLNode.
[exec] [wsejbdeploy] error: Class org.hibernate.type.AbstractType contains an invalid argument type in method setToX
MLNode.
[exec] [wsejbdeploy] error: Class org.hibernate.type.AbstractType contains an invalid argument type in method setToX
MLNode.
[exec] [wsejbdeploy] error: Class org.hibernate.collection.PersistentCollection contains an invalid argument type in
method initializeFromCache.
[exec] [wsejbdeploy] error: Class org.hibernate.collection.PersistentCollection contains an invalid argument type in
method initializeFromCache.
[exec] [wsejbdeploy] error: Class org.hibernate.collection.PersistentCollection contains an invalid argument type in
method initializeFromCache.
[exec] [wsejbdeploy] error: Class org.hibernate.engine.SessionImplementor contains an invalid argument type in metho
d initializeCollection.
[exec] [wsejbdeploy] error: Class org.hibernate.engine.SessionImplementor contains an invalid argument type in metho
d initializeCollection.
[exec] [wsejbdeploy] error: Class org.hibernate.metadata.ClassMetadata contains an invalid argument type in method g
etPropertyValuesToInsert.
[exec] [wsejbdeploy] error: Class org.hibernate.SessionFactory contains an invalid argument type in method getClassM
etadata.
[exec] [wsejbdeploy] error: Class org.hibernate.classic.Session contains an invalid argument type in method getSessi
on.
[exec] [wsejbdeploy] error: Class org.hibernate.engine.SessionFactoryImplementor contains an invalid argument type i
n method openSession.
[exec] [wsejbdeploy] error: Class org.hibernate.type.Type contains an invalid argument type in method isEqual.
[exec] [wsejbdeploy] error: Class PurchaseOrderLine contains an invalid return type.
[exec] [wsejbdeploy] error: Class com.xxx.yyy.service.zzz.payment.domain.entity.PurchaseOrder contains an in
valid argument type in method addOrderLine.
[exec] [wsejbdeploy] error: Class com.xxx.yyy.service.zzz.PaymentHandler contains an invalid argument typ
e in method requestPaymentAuthorisation.
[exec] [wsejbdeploy] 18 errors
[exec]
[exec]
[exec] [wsejbdeploy]
[exec] [wsejbdeploy] Updating.
[exec] [wsejbdeploy]
[exec] [wsejbdeploy] [*Error] An unexpected exception was thrown. Halting execution.
Comments on trace above in reverse order to follow stack trace:
[exec] [wsejbdeploy] error: Class com.xxx.yyy.service.zzz.payment.domain.entity.PurchaseOrder contains an in
valid argument type in method addOrderLine.
(The addOrderLine method takes a PurchaseOrderLine object as argument, so I guess that is the class to investigate further)
[exec] [wsejbdeploy] error: Class PurchaseOrderLine contains an invalid return type.
This class refers to a number of other objects, but only one was changed in the upgrade to hibernate3. The MonetaryAmount class which implements the CompositeUserType class.
This class is listed here:
Code:
/*
* Created on 26.nov.04
*
*/
package com.xxx.yyy.service.zzz.payment.domain.customtype;
import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.Currency;
import org.hibernate.usertype.CompositeUserType;
import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.type.Type;
public class MonetaryAmount implements CompositeUserType, CustomType {
static final long serialVersionUID = -1201650653566116913L;
private int[] TYPES = { Types.VARCHAR, Types.DECIMAL };
private Currency currency;
private BigDecimal amount;
public MonetaryAmount() {
}
public MonetaryAmount(final BigDecimal amt) {
this.amount = amt;
this.currency = Currency.getInstance("NOK");
}
public MonetaryAmount(Currency currency, BigDecimal amount) {
this.currency = currency;
this.amount = amount;
}
/* (non-Javadoc)
* @see org.hibernate.usertype.UserType#deepCopy(java.lang.Object)
*/
public Object deepCopy(Object arg0) throws HibernateException {
if(arg0 == null)
return null;
MonetaryAmount result = null;
if (!(arg0 instanceof MonetaryAmount)) {
throw new IllegalArgumentException(
"Can not perform deepCopy of objects of type " +
arg0.getClass().getName());
}
result = new MonetaryAmount(currency, amount);
return result;
}
/**
* @see org.hibernate.usertype.UserType#hashCode(java.lang.Object)
*/
public int hashCode(Object arg0) throws HibernateException {
return arg0.hashCode();
}
/*
* (non-Javadoc)
*
* @see org.hibernate.usertype.CompositeUserType#replace(java.lang.Object, java.lang.Object,
* org.hibernate.engine.SessionImplementor, java.lang.Object)
*/
public Object replace(Object original, Object target, SessionImplementor session, Object owner)
throws HibernateException {
return deepCopy(original);
}
/**
* @see org.hibernate.usertype.UserType#equals(java.lang.Object, java.lang.Object)
*/
public boolean equals(Object x, Object y) throws HibernateException {
if(x == y) {
return true;
}
MonetaryAmount a1 = (MonetaryAmount) x;
MonetaryAmount a2 = (MonetaryAmount) y;
if ((a1 == null) || (a2 == null) || (a1.getCurrency() == null)) {
return false;
}
return (a1.getAmount().equals(a2.getAmount()) && a1.getCurrency().equals(a2.getCurrency()));
}
/**
* @see org.hibernate.usertype.UserType#isMutable()
*/
public boolean isMutable() {
return false;
}
/**
* @see org.hibernate.usertype.UserType#nullSafeGet(java.sql.ResultSet, java.lang.String[], java.lang.Object)
*/
public Object nullSafeGet(ResultSet rs, String[] names,
SessionImplementor session, Object owner)
throws HibernateException, SQLException {
Currency currency = (Currency) Hibernate.CURRENCY.nullSafeGet(rs,
names[0]);
BigDecimal amount = (BigDecimal) Hibernate.BIG_DECIMAL.nullSafeGet(rs,
names[1]);
return new MonetaryAmount(currency, amount);
}
/**
* @see org.hibernate.usertype.UserType#nullSafeSet(java.sql.PreparedStatement, java.lang.Object, int)
*/
public void nullSafeSet(PreparedStatement st, Object value, int index,
SessionImplementor session) throws HibernateException, SQLException {
MonetaryAmount monetaryAmount = (MonetaryAmount) value;
Currency currency = null;
BigDecimal amount = null;
if (value != null) {
currency = monetaryAmount.getCurrency();
amount = monetaryAmount.getAmount();
}
Hibernate.CURRENCY.nullSafeSet(st, currency, index);
Hibernate.BIG_DECIMAL.nullSafeSet(st, amount, index + 1);
}
/**
* @see org.hibernate.usertype.UserType#returnedClass()
*/
public Class returnedClass() {
return MonetaryAmount.class;
}
/**
* @see org.hibernate.usertype.UserType#sqlTypes()
*/
public int[] sqlTypes() {
return TYPES;
}
/**
* property getter
* @return
*/
public BigDecimal getAmount() {
return amount;
}
/**
* property getter
* @return
*/
public Currency getCurrency() {
return currency;
}
/**
* @see org.hibernate.usertype.CompositeUserType#getPropertyNames()
*/
public String[] getPropertyNames() {
return new String[] { "currency", "amount" };
}
/**
* @see org.hibernate.usertype.CompositeUserType#getPropertyTypes()
*/
public Type[] getPropertyTypes() {
return new Type[] { Hibernate.CURRENCY, Hibernate.BIG_DECIMAL };
}
/**
* @see org.hibernate.usertype.CompositeUserType#getPropertyValue(java.lang.Object, int)
*/
public Object getPropertyValue(Object component, int property)
throws HibernateException {
Object result;
switch (property) {
case 0:
result = getCurrency();
break;
case 1:
result = getAmount();
break;
default:
throw new IndexOutOfBoundsException(
"known indexes are: 0=currency, 1=amount");
}
return result;
}
/**
* @see org.hibernate.usertype.CompositeUserType#setPropertyValue(java.lang.Object, int, java.lang.Object)
*/
public void setPropertyValue(Object component, int property, Object value)
throws HibernateException {
switch (property) {
case 0:
currency = (Currency) value;
break;
case 1:
amount = (BigDecimal) value;
break;
default:
throw new IndexOutOfBoundsException(
"known indexes are: 0=currency, 1=amount");
}
}
/**
* @see org.hibernate.usertype.CompositeUserType#disassemble(java.lang.Object, org.hibernate.engine.SessionImplementor)
*/
public Serializable disassemble(Object value, SessionImplementor session)
throws HibernateException {
return (Serializable) deepCopy(value);
}
/**
* @see org.hibernate.usertype.CompositeUserType#assemble(java.io.Serializable, org.hibernate.engine.SessionImplementor, java.lang.Object)
*/
public Object assemble(Serializable cached, SessionImplementor session,
Object owner) throws HibernateException {
return deepCopy(cached);
}
/**
*
* @see java.lang.Object#toString()
*/
public String toString() {
return currency + " " + amount;
}
}
The hashCode and replace methods are new to fulfill CompositeUserType changes.
Thanks in advance
Tomas Andersen