Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPA-Hibernate - "could not get a field value by reflection getter of .."

I try to use Hibernate 4.1.5.Final within a Spring MVC 3.1 application.

(Update : now Hibernate 4.1.6.Final and Spring 3.1.2.RELEASE, but still no luck!)

When I try to delete an entity I get an Exception I don't understand.

Here are the two main classes involved :

User :

@Entity
@Table(name="usertable")
public class User extends BaseModel
{ 
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY) 
    private long id;

    @OneToOne(optional=true, cascade=CascadeType.ALL, mappedBy="user", orphanRemoval=true, fetch=FetchType.LAZY)
    private FacebookAccount facebookAccount;


    // ...

    public long getId()
    {
        return id;
    }

    public void setId(long id)
    {
        this.id = id;
    }

    public FacebookAccount getFacebookAccount()
    {
        return facebookAccount;
    }

    public void setFacebookAccount(FacebookAccount facebookAccount)
    {
        this.facebookAccount = facebookAccount;
    }
}

FacebookAccount :

@Entity
@Table(name="facebookAccount")
public class FacebookAccount extends BaseModel
{
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY) 
    private Long id;

    @OneToOne
    private User user;

    // ...

}

Let's say I have a reference to a User that has a FacebookAccount. In a transaction (in a @Service) I try to do :

user.setFacebookAccount(null);
userRepository.save(user);  

I also tried :

user.setFacebookAccount(null);
facebookAccountRepository.delete(facebookAccount); 

With both, I get this exception :

org.springframework.orm.hibernate3.HibernateSystemException: could not get a field value by reflection getter of com.XXXXX.model.user.User.id; nested exception is org.hibernate.PropertyAccessException: could not get a field value by reflection getter of com.XXXXX.model.user.User.id
    at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:683) ~[spring-orm-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:104) ~[spring-orm-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:516) ~[spring-orm-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754) ~[spring-tx-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723) ~[spring-tx-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:393) ~[spring-tx-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:120) ~[spring-tx-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) ~[spring-aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) ~[spring-aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]

Why is that? getId() does exist in User and is public!

Any idea?

UPDATE :

I made some more tests and the conclusion is that the problem is "orphanRemoval=true". Without it, I'm able to delete the FacebookAccount using :

user.setFacebookAccount(null);
facebookAccountRepository.delete(facebookAccount); 

But this is not exactly what I want. I'd like the orphanRemoval to work!

UPDATE 2 :

It seems there is a problem with orphanRemoval and @OneToOne relations in JPA. I guess I have the same issue?

UPDATE 3 :

BaseModel class :

@MappedSuperclass
public abstract class BaseModel
{
    @Column(name = "dateCreated", nullable = false)
    private Date dateCreated;

    @Column(name = "dateModified", nullable = false)
    private Date dateModified;

    public Date getDateCreated()
    {
        return dateCreated;
    }

    public Date getDateModified()
    {
        return dateModified;
    }

    @PreUpdate
    @PrePersist
    @PreRemove
    protected void prePersist() 
    {
        Date now = DateUtil.now().toDate();
        if(dateCreated == null)
        {
            dateCreated = now;
        }
        dateModified = now;
    }

    @PostUpdate
    @PostPersist
    @PostRemove
    protected void postPersist() 
    {
    }

}

Stacktrace :

org.springframework.orm.hibernate3.HibernateSystemException: could not get a field value by reflection getter of com.XXXXX.model.user.User.id; nested exception is org.hibernate.PropertyAccessException: could not get a field value by reflection getter of com.XXXXX.model.user.User.id
    at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:683) ~[spring-orm-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:104) ~[spring-orm-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:516) ~[spring-orm-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754) ~[spring-tx-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723) ~[spring-tx-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:393) ~[spring-tx-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:120) ~[spring-tx-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) ~[spring-aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) ~[spring-aop-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at com.XXXXX.web.controllers.myprofile.abc.SomeController.facebookAccountConfirmationFormPosted(SomeController.java:272) ~[SomeController.class:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0_22]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) ~[na:1.6.0_22]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0_22]
    at java.lang.reflect.Method.invoke(Method.java:597) ~[na:1.6.0_22]
    at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:212) ~[spring-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126) ~[spring-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96) ~[spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617) ~[spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578) ~[spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80) ~[spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:900) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789) [spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) [javax.servlet-2.5.0.v201103041518.jar:na]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) [javax.servlet-2.5.0.v201103041518.jar:na]
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:565) [jetty-servlet-7.6.2.v20120308.jar:7.6.2.v20120308]
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1360) [jetty-servlet-7.6.2.v20120308.jar:7.6.2.v20120308]
    at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:147) [spring-orm-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) [spring-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1331) [jetty-servlet-7.6.2.v20120308.jar:7.6.2.v20120308]
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) [spring-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) [spring-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1331) [jetty-servlet-7.6.2.v20120308.jar:7.6.2.v20120308]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:311) [spring-security-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:116) [spring-security-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83) [spring-security-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) [spring-security-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113) [spring-security-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) [spring-security-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:101) [spring-security-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) [spring-security-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113) [spring-security-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) [spring-security-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:146) [spring-security-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) [spring-security-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54) [spring-security-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) [spring-security-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45) [spring-security-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) [spring-security-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:182) [spring-security-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) [spring-security-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105) [spring-security-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) [spring-security-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87) [spring-security-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) [spring-security-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at com.XXXXX.util.security.beanutils.AuthenticationManager.doFilter(AuthenticationManager.java:127) [AuthenticationManager.class:na]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) [spring-security-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:173) ~[spring-security-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) ~[spring-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259) ~[spring-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1331) [jetty-servlet-7.6.2.v20120308.jar:7.6.2.v20120308]
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) ~[spring-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) [spring-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1331) [jetty-servlet-7.6.2.v20120308.jar:7.6.2.v20120308]
    at com.XXXXX.util.web.filters.SaveGeneratedDynamicResourcesContentFilter.doFilter(SaveGeneratedDynamicResourcesContentFilter.java:60) ~[SaveGeneratedDynamicResourcesContentFilter.class:na]
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1331) [jetty-servlet-7.6.2.v20120308.jar:7.6.2.v20120308]
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:477) ~[na:na]
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119) ~[na:na]
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:524) ~[na:na]
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:227) ~[na:na]
    at org.eclipse.jetty.server.handler.ContextHandler.__doHandle(ContextHandler.java:1031) ~[na:na]
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java) ~[na:na]
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:406) ~[na:na]
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:186) ~[na:na]
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:965) ~[na:na]
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117) ~[na:na]
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:250) ~[na:na]
    at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:149) ~[na:na]
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:111) ~[na:na]
    at org.eclipse.jetty.server.Server.handle(Server.java:349) ~[na:na]
    at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:452) ~[na:na]
    at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:894) ~[na:na]
    at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:948) ~[na:na]
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:857) ~[na:na]
    at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235) ~[na:na]
    at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:77) ~[na:na]
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:609) ~[na:na]
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:45) ~[na:na]
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:599) ~[na:na]
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:534) ~[na:na]
    at java.lang.Thread.run(Thread.java:662) ~[na:1.6.0_22]
Caused by: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of com.XXXXX.model.user.User.id
    at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:62) ~[hibernate-core-4.1.6.Final.jar:4.1.6.Final]
    at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:341) ~[hibernate-core-4.1.6.Final.jar:4.1.6.Final]
    at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:4425) ~[hibernate-core-4.1.6.Final.jar:4.1.6.Final]
    at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:4147) ~[hibernate-core-4.1.6.Final.jar:4.1.6.Final]
    at org.hibernate.engine.internal.ForeignKeys.isTransient(ForeignKeys.java:209) ~[hibernate-core-4.1.6.Final.jar:4.1.6.Final]
    at org.hibernate.event.internal.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:102) ~[hibernate-core-4.1.6.Final.jar:4.1.6.Final]
    at org.hibernate.internal.SessionImpl.fireDelete(SessionImpl.java:954) ~[hibernate-core-4.1.6.Final.jar:4.1.6.Final]
    at org.hibernate.internal.SessionImpl.delete(SessionImpl.java:939) ~[hibernate-core-4.1.6.Final.jar:4.1.6.Final]
    at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:262) ~[hibernate-core-4.1.6.Final.jar:4.1.6.Final]
    at org.hibernate.engine.internal.Cascade.cascade(Cascade.java:165) ~[hibernate-core-4.1.6.Final.jar:4.1.6.Final]
    at org.hibernate.event.internal.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:160) ~[hibernate-core-4.1.6.Final.jar:4.1.6.Final]
    at org.hibernate.event.internal.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:151) ~[hibernate-core-4.1.6.Final.jar:4.1.6.Final]
    at org.hibernate.event.internal.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:88) ~[hibernate-core-4.1.6.Final.jar:4.1.6.Final]
    at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51) ~[hibernate-core-4.1.6.Final.jar:4.1.6.Final]
    at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1214) ~[hibernate-core-4.1.6.Final.jar:4.1.6.Final]
    at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:403) ~[hibernate-core-4.1.6.Final.jar:4.1.6.Final]
    at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101) ~[hibernate-core-4.1.6.Final.jar:4.1.6.Final]
    at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:175) ~[hibernate-core-4.1.6.Final.jar:4.1.6.Final]
    at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:75) ~[hibernate-entitymanager-4.1.6.Final.jar:4.1.6.Final]
    at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:512) ~[spring-orm-3.1.0.RELEASE.jar:3.1.0.RELEASE]
    ... 89 common frames omitted
Caused by: java.lang.IllegalArgumentException: Can not set long field com.XXXXX.model.user.User.id to com.XXXXX.model.social.FacebookAccount
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:146) ~[na:1.6.0_22]
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:150) ~[na:1.6.0_22]
    at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:37) ~[na:1.6.0_22]
    at sun.reflect.UnsafeLongFieldAccessorImpl.getLong(UnsafeLongFieldAccessorImpl.java:42) ~[na:1.6.0_22]
    at sun.reflect.UnsafeLongFieldAccessorImpl.get(UnsafeLongFieldAccessorImpl.java:18) ~[na:1.6.0_22]
    at java.lang.reflect.Field.get(Field.java:358) ~[na:1.6.0_22]
    at org.hibernate.property.DirectPropertyAccessor$DirectGetter.get(DirectPropertyAccessor.java:59) ~[hibernate-core-4.1.6.Final.jar:4.1.6.Final]
    ... 108 common frames omitted

UPDATE 4 :

A full and minimal application to reproduce the issue. The issue seems to happen using my project web structure (controller/service/repository) so there are no unit tests in the application. Instead, you have to run :

mvn clean jetty:run

Then point your browser to :

http://localhost:8080/

to trigger the exception. The controller#method that will be called is com.example.web.controllers.TestController#test().

like image 886
electrotype Avatar asked Aug 17 '12 16:08

electrotype


2 Answers

try to change the mapped :

http://www.coderanch.com/t/542400/ORM/databases/delete-option-cascade-Hibernate-one

like image 200
romu31 Avatar answered Sep 19 '22 09:09

romu31


You can check this implementation https://github.com/bondarenko/so-12009955 of your issue. It's working smoothly on my end.

like image 30
Oleksandr Bondarenko Avatar answered Sep 18 '22 09:09

Oleksandr Bondarenko