I'm attempting to save a hibernate-generated class in a servlet using jboss
4.0.2 and the Java 1.5.0.03 jdk. Can anyone shed light on why the following
doPost method fails at (1) below with an IllegalArgumentException exception
(ERROR [BasicPropertyAccessor] expected type: java.lang.Long, actual value:
java.lang.Long)? I've included the console output, server.log, Address.hbm.xml,
hibernate-service.xml, and the generated Address.java. Thanks in advance.
public class DataServlet extends HttpServlet {
|
| protected void doPost(
| HttpServletRequest request,
| HttpServletResponse response) throws ServletException, IOException {
| ...
| try {
| session = HibernateUtil.currentSession();
| tx = session.beginTransaction();
| Address address = new Address();
| address.setStreet("home");
| (1) session.save(address);
| tx.commit();
| } catch(PropertyAccessException e){
| (2) szErrorMsg = e.getMessage();
| tx.rollback();
| } finally {
| }
| ...
|
e.getMessage() at (2) above returns ...
---------------------------------------------
IllegalArgumentException occurred while calling setter of
testweb1.data.Address.id
Eclipse 3.0.2 console shows ...
-----------------------------------
16:59:13,699 ERROR [BasicPropertyAccessor] IllegalArgumentException in class:
testweb1.data.Address, setter method of property: id
16:59:13,699 ERROR [BasicPropertyAccessor] expected type: java.lang.Long,
actual value: java.lang.Long
D:\JBoss\jboss-4.0.2\server\default\log\server.log (snippet) ...
-------------------------------------------------------------------------
2005-07-04 16:59:06,509 DEBUG [org.hibernate.impl.SessionFactoryObjectFactory]
JNDI lookup: hibernate/TestWeb1SessionFactory
2005-07-04 16:59:06,509 DEBUG [org.hibernate.impl.SessionFactoryObjectFactory]
lookup: uid=402881e404e3db4f0104e3dbdf3a0001
2005-07-04 16:59:06,799 DEBUG [org.hibernate.jdbc.JDBCContext] no active
transaction, could not register Synchronization
2005-07-04 16:59:06,799 DEBUG [org.hibernate.impl.SessionImpl] opened session
at timestamp: 4589626763464704
2005-07-04 16:59:10,204 DEBUG [org.hibernate.transaction.JTATransaction] begin
2005-07-04 16:59:10,214 DEBUG [org.hibernate.transaction.JTATransaction]
Looking for UserTransaction under: UserTransaction
2005-07-04 16:59:10,234 DEBUG [org.hibernate.transaction.JTATransaction]
Obtained UserTransaction
2005-07-04 16:59:10,234 DEBUG [org.hibernate.transaction.JTATransaction] Began
a new JTA transaction
2005-07-04 16:59:10,254 DEBUG [org.hibernate.jdbc.JDBCContext] successfully
registered Synchronization
2005-07-04 16:59:13,659 DEBUG
[org.hibernate.event.def.DefaultSaveOrUpdateEventListener] saving transient
instance
2005-07-04 16:59:13,669 DEBUG [org.hibernate.jdbc.AbstractBatcher] opening JDBC
connection
2005-07-04 16:59:13,669 DEBUG [org.hibernate.id.IncrementGenerator] fetching
initial value: select max(ADDRESS_ID) from ADDRESS
2005-07-04 16:59:13,669 DEBUG [org.hibernate.SQL] select max(ADDRESS_ID) from
ADDRESS
2005-07-04 16:59:13,679 DEBUG [org.hibernate.id.IncrementGenerator] first free
id: 1
2005-07-04 16:59:13,679 DEBUG
[org.hibernate.event.def.AbstractSaveEventListener] generated identifier: 1,
using strategy: org.hibernate.id.IncrementGenerator
2005-07-04 16:59:13,689 DEBUG
[org.hibernate.event.def.AbstractSaveEventListener] saving
[testweb1.data.Address#1]
2005-07-04 16:59:13,699 ERROR [org.hibernate.property.BasicPropertyAccessor]
IllegalArgumentException in class: testweb1.data.Address, setter method of
property: id
2005-07-04 16:59:13,699 ERROR [org.hibernate.property.BasicPropertyAccessor]
expected type: java.lang.Long, actual value: java.lang.Long
2005-07-04 16:59:23,003 DEBUG [org.hibernate.transaction.JTATransaction]
rollback
2005-07-04 16:59:23,013 DEBUG [org.hibernate.transaction.CacheSynchronization]
transaction after completion callback, status: 4
2005-07-04 16:59:23,013 DEBUG [org.hibernate.jdbc.JDBCContext] after
transaction completion
2005-07-04 16:59:23,013 DEBUG [org.hibernate.impl.SessionImpl] after
transaction completion
2005-07-04 16:59:23,013 DEBUG [org.hibernate.transaction.CacheSynchronization]
automatically closing session
2005-07-04 16:59:23,013 DEBUG [org.hibernate.impl.SessionImpl] automatically
closing session
2005-07-04 16:59:23,013 DEBUG [org.hibernate.impl.SessionImpl] closing session
2005-07-04 16:59:23,013 DEBUG [org.hibernate.jdbc.AbstractBatcher] closing JDBC
connection (open PreparedStatements: 0, globally: 0) (open ResultSets: 0,
globally: 0)
2005-07-04 16:59:23,013 DEBUG [org.hibernate.jdbc.JDBCContext] after
transaction completion
2005-07-04 16:59:23,013 DEBUG [org.hibernate.impl.SessionImpl] after
transaction completion
2005-07-04 16:59:23,023 DEBUG [org.hibernate.transaction.JTATransaction] Rolled
back JTA UserTransaction
Address.hbm.xml
--------------------
<?xml version="1.0"?>
| <!DOCTYPE hibernate-mapping PUBLIC
| "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
| "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
|
| <hibernate-mapping package="testweb1.data">
| <class name="Address" table="ADDRESS">
| <id name="id" type="long" column="ADDRESS_ID">
| <generator class="increment"/>
| </id>
| <property name="street" type="string" column="STREET"/>
| </class>
|
| </hibernate-mapping>
|
hibernate-service.xml
-------------------------
<?xml version="1.0" encoding="UTF-8"?>
| <server>
| <mbean code="org.jboss.hibernate.jmx.Hibernate"
name="jboss.har:service=Hibernate">
| <attribute name="DatasourceName">java:/DefaultDS</attribute>
| <attribute
name="Dialect">org.hibernate.dialect.HSQLDialect</attribute>
| <attribute name="SessionFactoryName">
| java:/hibernate/TestWeb1SessionFactory
| </attribute>
| <attribute name="CacheProviderClass">
| org.hibernate.cache.HashtableCacheProvider
| </attribute>
| <attribute name="Hbm2ddlAuto">create</attribute>
| <!-- <attribute name="ShowSqlEnabled">true</attribute> -->
| <attribute name="ReflectionOptimizationEnabled">false</attribute>
| </mbean>
| </server>
|
Address.java
---------------
package testweb1.data;
|
| import java.util.*;
|
|
|
|
| /**
| * Address generated by hbm2java
| */
| public class Address implements java.io.Serializable {
|
| // Fields
|
| private Long id;
| private String street;
|
|
| // Constructors
|
| /** default constructor */
| public Address() {
| }
|
| /** constructor with id */
| public Address(Long id) {
| this.id = id;
| }
|
|
|
|
| // Property accessors
|
| /**
| *
| */
| public Long getId() {
| return this.id;
| }
|
| public void setId(Long id) {
| this.id = id;
| }
|
| /**
| *
| */
| public String getStreet() {
| return this.street;
| }
|
| public void setStreet(String street) {
| this.street = street;
| }
|
|
|
| }
|
View the original post :
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3883600#3883600
Reply to the post :
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3883600
-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user