-->
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.  [ 18 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: can't get it work
PostPosted: Tue Jan 17, 2006 11:40 am 
Newbie

Joined: Tue Jan 17, 2006 11:21 am
Posts: 7
Hi all!
I'm using Hibernate 3.1 on JBoss 4.0.3 AS and a PostgreSQL 8.1 database as a datasource. I'm trying to use a simple POJO class with the stateless session bean, everything is ok, Hibernate even generate database schema ,but when I'm persisting the object with session.save method, I'm getting the following error:

17:24:01,046 INFO [STDOUT] Hibernate: select nextval ('cust_id_seq')
17:24:01,046 ERROR [BasicPropertyAccessor] IllegalArgumentException in class: hbm.Customer, setter method of property: id
17:24:01,046 ERROR [BasicPropertyAccessor] expected type: java.lang.Integer, actual value: java.lang.Integer
17:24:01,046 INFO [STDOUT] org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of hbm.Customer.id
at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:104)
at org.hibernate.tuple.AbstractEntityTuplizer.setIdentifier(AbstractEntityTuplizer.java:204)
at org.hibernate.persister.entity.AbstractEntityPersister.setIdentifier(AbstractEntityPersister.java:3262)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:157)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:114)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:544)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:533)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:529)
at ejb.CustomersBean.addCustomer(CustomersBean.java:94)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.jboss.invocation.Invocation.performCall(Invocation.java:345)
at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:214)
at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:149)
at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:154)
at org.jboss.webservice.server.ServiceEndpointInterceptor.invoke(ServiceEndpointInterceptor.java:54)
at org.jboss.ejb.plugins.CallValidationInterceptor.invoke(CallValidationInterceptor.java:48)
at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:106)
at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:335)
at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:166)
at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:153)
at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:192)
at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
at org.jboss.ejb.SessionContainer.internalInvoke(SessionContainer.java:624)
at org.jboss.ejb.Container.invoke(Container.java:873)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:245)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
at org.jboss.invocation.jrmp.server.JRMPInvoker$MBeanServerAction.invoke(JRMPInvoker.java:805)
at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:406)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:42)
... 53 more


POJO class...

/** @hibernate.class
* table = "customer"
*/
public class Customer implements Serializable{
public Integer id=null;
private String name="";
private String surname="";

/** @hibernate.id
* column = "cust_id"
* type = "java.lang.Integer"
* generator-class = "sequence"
* @hibernate.generator-param
* name = "sequence"
* value = "cust_id_seq"
*/
public Integer getId() {
return this.id;
}
private void setId(Integer id) {
this.id = id;
}

/** @hibernate.property
* column = "cust_name"
* type = "string"
*/
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

/** @hibernate.property
* column = "curs_surname"
* type = "string"
*/
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}

public Customer() {
super();
}
}

Mapping file generated by XDoclet...

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping
>
<class
name="hbm.Customer"
table="customer"
>

<id
name="id"
column="cust_id"
type="java.lang.Integer"
>
<generator class="sequence">
<param name="sequence">cust_id_seq</param>
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-Customer.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>
<property
name="name"
type="string"
update="true"
insert="true"
column="cust_name"
/>
<property
name="surname"
type="string"
update="true"
insert="true"
column="curs_surname"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Customer.xml
containing the additional properties and place it in your merge dir.
-->

</class>
</hibernate-mapping>

and a cut from Session Bean

SessionFactory sf = null;
String jndiName = "java:/hibernate/TestSessionFactory";
try {
sf = (SessionFactory) ctx.lookup(jndiName);
} catch (NamingException e) {
cat.error("Naming Failed!",e);
}

Session session = sf.getCurrentSession();

Customer cust = new Customer();
cust.setName(name);
cust.setSurname(surname);

try {
session.save(cust);
} catch (HibernateException e) {
e.printStackTrace();
}
session.close();

Maybe i'm doing something wrong?

Simon[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 17, 2006 9:55 pm 
Newbie

Joined: Tue Jan 10, 2006 1:30 pm
Posts: 14
Hmm, This line doesn't look right. I'm not familiar with the tools designed to generate the mapping files. Hope this gets the ball rolling...

<id
name="id"
column="cust_id"
type="java.lang.Integer"
>
<generator class="sequence">
<param name="sequence">cust_id_seq</param>
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-Customer.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>

Hibernate Example:
<id name="id" type="long" column="cat_id">
<generator class="org.hibernate.id.TableHiLoGenerator">
<param name="table">uid_table</param>
<param name="column">next_hi_value_column</param>
</generator>
</id>

_________________
Brian


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 17, 2006 9:57 pm 
Newbie

Joined: Tue Jan 10, 2006 1:30 pm
Posts: 14
cokerbl wrote:
Hmm, This line doesn't look right. I'm not familiar with the tools designed to generate the mapping files. Hope this gets the ball rolling...

<id
name="id"
column="cust_id"
type="java.lang.Integer"
>
<generator class="sequence">
<param name="sequence">cust_id_seq</param>
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-Customer.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>

Hibernate Example:
<id name="id" type="long" column="cat_id">
<generator class="org.hibernate.id.TableHiLoGenerator">
<param name="table">uid_table</param>
<param name="column">next_hi_value_column</param>
</generator>
</id>


Oops, never mind. Your syntax is correct.

_________________
Brian


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 17, 2006 10:01 pm 
Newbie

Joined: Tue Jan 10, 2006 1:30 pm
Posts: 14
Ok, now that I've worked out the brain farts... I found your problem. Your setId method is private! Make that method public and it should work :-)

_________________
Brian


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 18, 2006 5:23 am 
Newbie

Joined: Tue Jan 17, 2006 11:21 am
Posts: 7
well,I guess it should work, but i've already tried every combination of making setId and getId private or public, I even tried to make the id field public and still no result. Besides, in documentation it is recomended to make your setters for ids private,just not to harm them ;) anyway, thanks for your replies.
Simon.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 18, 2006 1:01 pm 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
is the name of the sequence really cust_id_seq and not customer_cust_id_seq

Than of course as said before. setId should be public.

Does the error message change when setId is public?

Regards Sebastian

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 19, 2006 4:12 am 
Newbie

Joined: Tue Jan 17, 2006 11:21 am
Posts: 7
no, I tried to make a customer_cust_id_seq sequence as you said and setId method public and still I'm getting the same error. The most strange part of this exception for me is:
17:24:01,046 ERROR [BasicPropertyAccessor] expected type: java.lang.Integer, actual value: java.lang.Integer

I just can't understand it.
Simon.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 19, 2006 4:24 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
I meant, can you look in the db what the name of the sequence is.

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 19, 2006 4:47 am 
Newbie

Joined: Tue Jan 17, 2006 11:21 am
Posts: 7
In database the sequence is created by Hibernate exactly as I'm writing it in the settings : customer_cust_id_seq. That's the most strange thing, Hibernate correctly generates the table and sequence.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 19, 2006 4:55 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
Did you define an Integer type somewhere?

please try also (although it seems correct) to set the type in the mapping to
type="integer"

Sebastian

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 19, 2006 5:00 am 
Regular
Regular

Joined: Tue Jan 03, 2006 9:52 am
Posts: 52
Location: Zurich
Do you use "sequence" generator in other mappings as well? If so, do they work there?
You have probably reasons why to use "sequence". As I am using a database which does not support sequence, I cannot reproduce it.

But maybe you can try to use "native" (more portable) and long instead of java.lang.Integer?
Just a proposal (maybe a workaround)
Urs


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 19, 2006 5:15 am 
Newbie

Joined: Tue Jan 17, 2006 11:21 am
Posts: 7
Quote:
Do you use "sequence" generator in other mappings as well? If so, do they work there?
You have probably reasons why to use "sequence". As I am using a database which does not support sequence, I cannot reproduce it.

But maybe you can try to use "native" (more portable) and long instead of java.lang.Integer?
Just a proposal (maybe a workaround)
Urs

I tried to use native, in PostgreSQL it also generates sequence,so in this way i think it is useful to directly tell Hibernate what to use. Long type is no use instead of writing me
ERROR [BasicPropertyAccessor] expected type: java.lang.Integer, actual value: java.lang.Integer
it is writing
ERROR [BasicPropertyAccessor] expected type: java.lang.Long, actual value: java.lang.Long


Quote:
Did you define an Integer type somewhere?

please try also (although it seems correct) to set the type in the mapping to
type="integer"


What do you mean define an Integer somewhere, it is java.lang.Integer isn't it? With type="integer" I get the same exception :(


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 19, 2006 3:26 pm 
Newbie

Joined: Tue Jan 03, 2006 7:30 am
Posts: 18
Location: Budapest, Hungary
This is most probably a classloader issue... Are you accessing the session bean through its local interface? If yes, do you get this error if you switch to the remote interface?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 19, 2006 11:52 pm 
Regular
Regular

Joined: Tue Dec 14, 2004 5:21 am
Posts: 104
Location: india
tpalfalvi wrote:
This is most probably a classloader issue... Are you accessing the session bean through its local interface? If yes, do you get this error if you switch to the remote interface?


yeah , this can be a reason .
there is no error with the mappings and <param sequence ...> doesnt have anything to do with the error .
check for any class path issues too

_________________
sHeRiN
thanks for your ratings ...... :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 20, 2006 10:18 am 
Newbie

Joined: Tue Jan 17, 2006 11:21 am
Posts: 7
Well this looks like a remote session bean to me:
/**
* @ejb.bean name="Customers"
* display-name="Name for Customers"
* description="Description for Customers"
* jndi-name="ejb/Customers"
* type="Stateless"
* view-type="remote"
*/
public class CustomersBean implements SessionBean {

bla bla bla...

/**
* Business method
* @ejb.interface-method view-type = "remote"
*/
public void addCustomer(String name, String surname) {
Context ctx=null;
SessionFactory sf = null;
String jndiName = "java:/hibernate/TestSessionFactory";
try {
sf = (SessionFactory) ctx.lookup(jndiName);
} catch (NamingException e) {
cat.error("Naming Failed!",e);
}

Session session = sf.getCurrentSession();

Customer cust = new Customer();
cust.setName(name);
cust.setSurname(surname);

try {
session.save(cust);
} catch (HibernateException e) {
e.printStackTrace();
}

this class is generated with JBoss IDE 1.5

Ok,and client class:

public class MainClass {
private static Customers customers=null;

public static void main(String[] args) {
Hashtable ht = new Hashtable();
Properties properties = new Properties();
properties.put("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
properties.put("java.naming.factory.url.pkgs",
"org.jboss.naming:org.jnp.interfaces");
properties.put("java.naming.provider.url", "jnp://localhost:1099");
properties.put("jnp.disableDiscovery", "true");
try {
Context context = new InitialContext(properties);
Object ref = context.lookup("ejb/Customers");
CustomersHome home = (CustomersHome)PortableRemoteObject.narrow(ref, CustomersHome.class);
customers = home.create();
customers.addCustomer("Andy","Webber");
}
catch(Exception e) {
e.printStackTrace();
}
finally {
if(customers!=null) {
try {
customers.remove();
}
catch(Exception ex) {
ex.printStackTrace();
}
}
}
}
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 18 posts ]  Go to page 1, 2  Next

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.