i have two entity one with @Id an other with @EmbeddedId
and whe i try to merge the class with i get
17:49:54,131 ERROR [BasicPropertyAccessor] IllegalArgumentException in class: com.marcos.model.Ciudad, getter method of property: id
17:49:54,132 SEVERE [marcosEJBPU] update failed
javax.persistence.PersistenceException: org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of com.marcos.model.Ciudad.id
at org.hibernate.ejb.AbstractEntityManagerImpl.throwP ersistenceException(AbstractEntityManagerImpl.java :614)
at org.hibernate.ejb.AbstractEntityManagerImpl.merge( AbstractEntityManagerImpl.java:244)
at org.jboss.ejb3.entity.ExtendedEntityManager.merge( ExtendedEntityManager.java:106)
at com.marcos.model.PaisFacade.update(PaisFacade.java :83)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.aop.joinpoint.MethodInvocation.invokeTar get(MethodInvocation.java:122)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:111)
at org.jboss.ejb3.EJBContainerInvocationWrapper.invok eNext(EJBContainerInvocationWrapper.java:69)
at org.jboss.ejb3.interceptors.aop.InterceptorSequenc er.invoke(InterceptorSequencer.java:73)
at org.jboss.ejb3.interceptors.aop.InterceptorSequenc er.aroundInvoke(InterceptorSequencer.java:59)
at sun.reflect.GeneratedMethodAccessor324.invoke(Unkn own Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jboss.aop.advice.PerJoinpointAdvice.invoke(Per JoinpointAdvice.java:174)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:102)
at org.jboss.ejb3.interceptors.aop.InvocationContextI nterceptor.fillMethod(InvocationContextInterceptor .java:72)
at org.jboss.aop.advice.org.jboss.ejb3.interceptors.a op.InvocationContextInterceptor_z_fillMethod_95603 87.invoke(InvocationContextInterceptor_z_fillMetho d_9560387.java)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:102)
at org.jboss.ejb3.interceptors.aop.InvocationContextI nterceptor.setup(InvocationContextInterceptor.java :88)
at org.jboss.aop.advice.org.jboss.ejb3.interceptors.a op.InvocationContextInterceptor_z_setup_9560387.in voke(InvocationContextInterceptor_z_setup_9560387. java)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:102)
at org.jboss.ejb3.connectionmanager.CachedConnectionI nterceptor.invoke(CachedConnectionInterceptor.java :62)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:102)
at org.jboss.ejb3.entity.ExtendedPersistenceContextPr opagationInterceptor.invoke(ExtendedPersistenceCon textPropagationInterceptor.java:74)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:102)
at org.jboss.ejb3.entity.TransactionScopedEntityManag erInterceptor.invoke(TransactionScopedEntityManage rInterceptor.java:56)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:102)
at org.jboss.ejb3.AllowedOperationsInterceptor.invoke (AllowedOperationsInterceptor.java:47)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:102)
at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInter ceptor.java:42)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:102)
at org.jboss.ejb3.stateful.StatefulInstanceIntercepto r.invoke(StatefulInstanceInterceptor.java:81)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:102)
at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPoli cy.java:79)
at org.jboss.aspects.tx.TxInterceptor$Required.invoke (TxInterceptor.java:190)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:102)
at org.jboss.aspects.tx.TxPropagationInterceptor.invo ke(TxPropagationInterceptor.java:76)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:102)
at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInter ceptor.java:42)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:102)
at org.jboss.ejb3.security.Ejb3AuthenticationIntercep torv2.invoke(Ejb3AuthenticationInterceptorv2.java: 186)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:102)
at org.jboss.ejb3.ENCPropagationInterceptor.invoke(EN CPropagationInterceptor.java:41)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:102)
at org.jboss.ejb3.BlockContainerShutdownInterceptor.i nvoke(BlockContainerShutdownInterceptor.java:67)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:102)
at org.jboss.aspects.currentinvocation.CurrentInvocat ionInterceptor.invoke(CurrentInvocationInterceptor .java:67)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNex t(MethodInvocation.java:102)
at org.jboss.ejb3.session.SessionSpecContainer.invoke (SessionSpecContainer.java:176)
at org.jboss.ejb3.session.SessionSpecContainer.invoke (SessionSpecContainer.java:216)
at org.jboss.ejb3.proxy.impl.handler.session.SessionP roxyInvocationHandlerBase.invoke(SessionProxyInvoc ationHandlerBase.java:207)
at org.jboss.ejb3.proxy.impl.handler.session.SessionP roxyInvocationHandlerBase.invoke(SessionProxyInvoc ationHandlerBase.java:164)
at $Proxy1311.update(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at flex.messaging.services.remoting.adapters.JavaAdap ter.invoke(JavaAdapter.java:421)
at flex.messaging.services.RemotingService.serviceMes sage(RemotingService.java:183)
at flex.messaging.MessageBroker.routeMessageToService (MessageBroker.java:1406)
at flex.messaging.endpoints.AbstractEndpoint.serviceM essage(AbstractEndpoint.java:1005)
at flex.messaging.endpoints.amf.MessageBrokerFilter.i nvoke(MessageBrokerFilter.java:103)
at flex.messaging.endpoints.amf.LegacyFilter.invoke(L egacyFilter.java:158)
at flex.messaging.endpoints.amf.SessionFilter.invoke( SessionFilter.java:44)
at flex.messaging.endpoints.amf.BatchProcessFilter.in voke(BatchProcessFilter.java:67)
at flex.messaging.endpoints.amf.SerializationFilter.i nvoke(SerializationFilter.java:166)
at flex.messaging.endpoints.BaseHTTPEndpoint.service( BaseHTTPEndpoint.java:308)
at flex.messaging.MessageBrokerServlet.service(Messag eBrokerServlet.java:364)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doF ilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:235)
at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:191)
at org.jboss.web.tomcat.security.SecurityAssociationV alve.invoke(SecurityAssociationValve.java:190)
at org.jboss.web.tomcat.security.JaccContextValve.inv oke(JaccContextValve.java:92)
at org.jboss.web.tomcat.security.SecurityContextEstab lishmentValve.process(SecurityContextEstablishment Valve.java:126)
at org.jboss.web.tomcat.security.SecurityContextEstab lishmentValve.invoke(SecurityContextEstablishmentV alve.java:70)
at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionV alve.invoke(CachedConnectionValve.java:158)
at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:330)
at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:829)
at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:598)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:595)
Caused by: org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of com.marcos.model.Ciudad.id
at org.hibernate.property.BasicPropertyAccessor$Basic Getter.get(BasicPropertyAccessor.java:195)
at org.hibernate.tuple.entity.AbstractEntityTuplizer. getIdentifier(AbstractEntityTuplizer.java:206)
at org.hibernate.persister.entity.AbstractEntityPersi ster.getIdentifier(AbstractEntityPersister.java:36 19)
at org.hibernate.event.def.DefaultMergeEventListener. onMerge(DefaultMergeEventListener.java:145)
at org.hibernate.impl.SessionImpl.fireMerge(SessionIm pl.java:714)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.j ava:696)
at org.hibernate.engine.CascadingAction$6.cascade(Cas cadingAction.java:268)
at org.hibernate.engine.Cascade.cascadeToOne(Cascade. java:291)
at org.hibernate.engine.Cascade.cascadeAssociation(Ca scade.java:239)
at org.hibernate.engine.Cascade.cascadeProperty(Casca de.java:192)
at org.hibernate.engine.Cascade.cascadeCollectionElem ents(Cascade.java:319)
at org.hibernate.engine.Cascade.cascadeCollection(Cas cade.java:265)
at org.hibernate.engine.Cascade.cascadeAssociation(Ca scade.java:242)
at org.hibernate.engine.Cascade.cascadeProperty(Casca de.java:192)
at org.hibernate.engine.Cascade.cascade(Cascade.java: 153)
at org.hibernate.event.def.DefaultMergeEventListener. cascadeOnMerge(DefaultMergeEventListener.java:459)
at org.hibernate.event.def.DefaultMergeEventListener. entityIsDetached(DefaultMergeEventListener.java:31 8)
at org.hibernate.event.def.DefaultMergeEventListener. onMerge(DefaultMergeEventListener.java:167)
at org.hibernate.event.def.DefaultMergeEventListener. onMerge(DefaultMergeEventListener.java:81)
at org.hibernate.impl.SessionImpl.fireMerge(SessionIm pl.java:704)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.j ava:688)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.j ava:692)
at org.hibernate.ejb.AbstractEntityManagerImpl.merge( AbstractEntityManagerImpl.java:235)
... 90 more
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.hibernate.property.BasicPropertyAccessor$Basic Getter.get(BasicPropertyAccessor.java:169)
... 112 more
HERE ARE THE CLASSES I USE
package com.marcos.model;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
/**
* Pais entity. @author MyEclipse Persistence Tools
*/
@Entity
@Table(name = "pais", catalog = "mymarcos"
public class Pais implements java.io.Serializable {
// Fields
private Short idpais;
private String nombre;
private Set<Ciudad> ciudads = new HashSet<Ciudad>(0);
// Constructors
/** default constructor */
public Pais() {
}
/** minimal constructor */
public Pais(String nombre) {
this.nombre = nombre;
}
/** full constructor */
public Pais(String nombre, Set<Ciudad> ciudads) {
this.nombre = nombre;
this.ciudads = ciudads;
}
// Property accessors
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "idpais", unique = true, nullable = false)
public Short getIdpais() {
return this.idpais;
}
public void setIdpais(Short idpais) {
this.idpais = idpais;
}
@Column(name = "nombre", nullable = false, length = 60)
public String getNombre() {
return this.nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "pais"
public Set<Ciudad> getCiudads() {
return this.ciudads;
}
public void setCiudads(Set<Ciudad> ciudads) {
this.ciudads = ciudads;
}
}
package com.marcos.model;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
/**
* Ciudad entity. @author MyEclipse Persistence Tools
*/
@Entity
@Table(name = "ciudad", catalog = "mymarcos"
public class Ciudad implements java.io.Serializable {
// Fields
private CiudadId id;
private Pais pais;
private String nombre;
private Set<Region> regions = new HashSet<Region>(0);
// Constructors
/** default constructor */
public Ciudad() {
}
/** minimal constructor */
public Ciudad(CiudadId id, Pais pais) {
this.id = id;
this.pais = pais;
}
/** full constructor */
public Ciudad(CiudadId id, Pais pais, String nombre, Set<Region> regions) {
this.id = id;
this.pais = pais;
this.nombre = nombre;
this.regions = regions;
}
// Property accessors
@EmbeddedId
@AttributeOverrides( {
@AttributeOverride(name = "idciudad", column = @Column(name = "idciudad", nullable = false)),
@AttributeOverride(name = "paisIdpais", column = @Column(name = "pais_idpais", nullable = false)) })
public CiudadId getId() {
return this.id;
}
public void setId(CiudadId id) {
this.id = id;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "pais_idpais", nullable = false, insertable = false, updatable = false)
public Pais getPais() {
return this.pais;
}
public void setPais(Pais pais) {
this.pais = pais;
}
@Column(name = "nombre", length = 45)
public String getNombre() {
return this.nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "ciudad"
public Set<Region> getRegions() {
return this.regions;
}
public void setRegions(Set<Region> regions) {
this.regions = regions;
}
}
package com.marcos.model;
import javax.persistence.Column;
import javax.persistence.Embeddable;
/**
* CiudadId entity. @author MyEclipse Persistence Tools
*/
@Embeddable
public class CiudadId implements java.io.Serializable {
// Fields
private Short idciudad;
private Short paisIdpais;
// Constructors
/** default constructor */
public CiudadId() {
}
/** full constructor */
public CiudadId(Short idciudad, Short paisIdpais) {
this.idciudad = idciudad;
this.paisIdpais = paisIdpais;
}
// Property accessors
@Column(name = "idciudad", nullable = false)
public Short getIdciudad() {
return this.idciudad;
}
public void setIdciudad(Short idciudad) {
this.idciudad = idciudad;
}
@Column(name = "pais_idpais", nullable = false)
public Short getPaisIdpais() {
return this.paisIdpais;
}
public void setPaisIdpais(Short paisIdpais) {
this.paisIdpais = paisIdpais;
}
public boolean equals(Object other) {
if ((this == other))
return true;
if ((other == null))
return false;
if (!(other instanceof CiudadId))
return false;
CiudadId castOther = (CiudadId) other;
return ((this.getIdciudad() == castOther.getIdciudad()) || (this
.getIdciudad() != null
&& castOther.getIdciudad() != null && this.getIdciudad()
.equals(castOther.getIdciudad())))
&& ((this.getPaisIdpais() == castOther.getPaisIdpais()) || (this
.getPaisIdpais() != null
&& castOther.getPaisIdpais() != null && this
.getPaisIdpais().equals(castOther.getPaisIdpais()) ));
}
public int hashCode() {
int result = 17;
result = 37 * result
+ (getIdciudad() == null ? 0 : this.getIdciudad().hashCode());
result = 37
* result
+ (getPaisIdpais() == null ? 0 : this.getPaisIdpais()
.hashCode());
return result;
}
}
package com.marcos.model;
import java.util.List;
import java.util.logging.Level;
import javax.ejb.Remove;
import javax.ejb.Stateful;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;
import javax.persistence.Query;
/**
* Facade for entity Pais.
*
* @see com.marcos.model.Pais
* @author MyEclipse Persistence Tools
*/
@Stateful
public class PaisFacade implements PaisFacadeLocal, PaisFacadeRemote {
// property constants
public static final String NOMBRE = "nombre";
@PersistenceContext(unitName="marcosEJBPU&quo t;, type=PersistenceContextType.EXTENDED)
private EntityManager entityManager;
/**
* Perform an initial save of a previously unsaved Pais entity. All
* subsequent persist actions of this entity should use the #update()
* method.
*
* @param entity
* Pais entity to persist
* @throws RuntimeException
* when the operation fails
*/
public void save(Pais entity) {
LogUtil.log("saving Pais instance", Level.INFO, null);
try {
entityManager.persist(entity);
LogUtil.log("save successful", Level.INFO, null);
} catch (RuntimeException re) {
LogUtil.log("save failed", Level.SEVERE, re);
throw re;
}
}
/**
* Delete a persistent Pais entity.
*
* @param entity
* Pais entity to delete
* @throws RuntimeException
* when the operation fails
*/
public void del(Pais entity) {
LogUtil.log("deleting Pais instance", Level.INFO, null);
try {
entity = entityManager.getReference(Pais.class, entity.getIdpais());
entityManager.remove(entity);
LogUtil.log("delete successful", Level.INFO, null);
} catch (RuntimeException re) {
LogUtil.log("delete failed", Level.SEVERE, re);
throw re;
}
}
/**
* Persist a previously saved Pais entity and return it or a copy of it to
* the sender. A copy of the Pais entity parameter is returned when the JPA
* persistence mechanism has not previously been tracking the updated
* entity.
*
* @param entity
* Pais entity to update
* @return Pais the persisted Pais entity instance, may not be the same
* @throws RuntimeException
* if the operation fails
*/
public Pais update(Pais entity) {
LogUtil.log("updating Pais instance", Level.INFO, null);
try {
Pais result = entityManager.merge(entity);
LogUtil.log("update successful", Level.INFO, null);
return result;
} catch (RuntimeException re) {
LogUtil.log("update failed", Level.SEVERE, re);
throw re;
}
}
public Pais findById(Short id) {
LogUtil.log("finding Pais instance with id: " + id, Level.INFO, null);
try {
Pais instance = entityManager.find(Pais.class, id);
return instance;
} catch (RuntimeException re) {
LogUtil.log("find failed", Level.SEVERE, re);
throw re;
}
}
/**
* Find all Pais entities with a specific property value.
*
* @param propertyName
* the name of the Pais property to query
* @param value
* the property value to match
* @return List<Pais> found by query
*/
@SuppressWarnings("unchecked"
public List<Pais> findByProperty(String propertyName, final Object value) {
LogUtil.log("finding Pais instance with property: " + propertyName
+ ", value: " + value, Level.INFO, null);
try {
final String queryString = "select model from Pais model where model."
+ propertyName + "= :propertyValue";
Query query = entityManager.createQuery(queryString);
query.setParameter("propertyValue", value);
return query.getResultList();
} catch (RuntimeException re) {
LogUtil.log("find by property name failed", Level.SEVERE, re);
throw re;
}
}
public List<Pais> findByNombre(Object nombre) {
return findByProperty(NOMBRE, nombre);
}
/**
* Find all Pais entities.
*
* @return List<Pais> all Pais entities
*/
@SuppressWarnings("unchecked"
public List<Pais> findAll() {
LogUtil.log("finding all Pais instances", Level.INFO, null);
try {
final String queryString = "select model from Pais model";
Query query = entityManager.createQuery(queryString);
return query.getResultList();
} catch (RuntimeException re) {
LogUtil.log("find all failed", Level.SEVERE, re);
throw re;
}
}
@Remove
public void finished(){
LogUtil.log("Bean destruido", Level.INFO, null);
}
}