The attribute [id] of class ... is mapped to a primary key column in the database

Hi,

I’m on CUBA 7 Beta 2. Following the Social Login documentation part (I want to login with Google), after extending my User model CUBA won’t start anymore.

2018-11-20 11:42:44.014 INFO [main/app-core/server] com.haulmont.cuba.core.sys.DefaultPermissionValuesConfig - Initializing default permission values
2018-11-20 11:42:44.125 ERROR [main] com.haulmont.cuba.core.sys.AbstractWebAppContextLoader - Error initializing application
javax.persistence.PersistenceException: Exception [EclipseLink-7251] (Eclipse Persistence Services - 2.7.2.2-cuba): org.eclipse.persistence.exceptions.ValidationException
Exception Description: The attribute [id] of class [xxxxx.entity.ExtUser] is mapped to a primary key column in the database. Updates are not allowed.

My ExtUser is:

@Entity(name = "metai4_ExtUser")
@Extends(User.class)
public class ExtUser extends User {
    @Column(name = "GOOGLE_ID")
    @Index(unique = true)
    protected String googleId;
    public String getGoogleId() {
        return googleId;
    }
    public void setGoogleId(String googleId) {
        this.googleId = googleId;
    }
}

The only reference to this problem I found in the forums is about the enhance / entitiesEnhancing gradle task from 6.10; I checked my config and it looks ok:

configure(globalModule) {
    entitiesEnhancing {
        main {
            enabled = true
        }
    }
}

What am I doing wrong?

ALSO note that I put in a @Index(unique=true) and it is ignored when creating DB scripts. It does work if the unique is set in the @Column().

Extra stacktrace:

javax.persistence.PersistenceException: Exception [EclipseLink-7251] (Eclipse Persistence Services - 2.7.2.2-cuba): org.eclipse.persistence.exceptions.ValidationException
Exception Description: The attribute [id] of class [xxxx.ExtUser] is mapped to a primary key column in the database. Updates are not allowed.
	at org.eclipse.persistence.internal.jpa.EntityManagerImpl.flush(EntityManagerImpl.java:976) ~[org.eclipse.persistence.jpa-2.7.2-2-cuba.jar:na]
	at com.haulmont.cuba.core.sys.persistence.PersistenceImplSupport$ContainerResourceSynchronization.detachAll(PersistenceImplSupport.java:496) ~[cuba-core-7.0-SNAPSHOT.jar:7.0-SNAPSHOT]
	at com.haulmont.cuba.core.sys.persistence.PersistenceImplSupport$ContainerResourceSynchronization.beforeCommit(PersistenceImplSupport.java:449) ~[cuba-core-7.0-SNAPSHOT.jar:7.0-SNAPSHOT]
	at org.springframework.transaction.support.TransactionSynchronizationUtils.triggerBeforeCommit(TransactionSynchronizationUtils.java:96) ~[spring-tx-5.1.2.RELEASE.jar:5.1.2.RELEASE]
	at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCommit(AbstractPlatformTransactionManager.java:922) ~[spring-tx-5.1.2.RELEASE.jar:5.1.2.RELEASE]
	at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:730) ~[spring-tx-5.1.2.RELEASE.jar:5.1.2.RELEASE]
	at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:714) ~[spring-tx-5.1.2.RELEASE.jar:5.1.2.RELEASE]
	at com.haulmont.cuba.core.sys.TransactionImpl.commit(TransactionImpl.java:104) ~[cuba-core-7.0-SNAPSHOT.jar:7.0-SNAPSHOT]
	at com.haulmont.cuba.security.auth.AuthenticationManagerBean.login(AuthenticationManagerBean.java:119) ~[cuba-core-7.0-SNAPSHOT.jar:7.0-SNAPSHOT]
	at com.haulmont.cuba.security.auth.AnonymousSessionHolder.loginAnonymous(AnonymousSessionHolder.java:82) ~[cuba-core-7.0-SNAPSHOT.jar:7.0-SNAPSHOT]
	at com.haulmont.cuba.security.auth.AnonymousSessionHolder.initializeAnonymousSession(AnonymousSessionHolder.java:72) ~[cuba-core-7.0-SNAPSHOT.jar:7.0-SNAPSHOT]
	at com.haulmont.cuba.security.auth.AnonymousSessionHolder.applicationStarted(AnonymousSessionHolder.java:45) ~[cuba-core-7.0-SNAPSHOT.jar:7.0-SNAPSHOT]
	at com.haulmont.cuba.core.sys.AppContext.startContext(AppContext.java:239) ~[cuba-global-7.0-SNAPSHOT.jar:7.0-SNAPSHOT]
	at com.haulmont.cuba.core.sys.AppContext$Internals.startContext(AppContext.java:302) ~[cuba-global-7.0-SNAPSHOT.jar:7.0-SNAPSHOT]
	at com.haulmont.cuba.core.sys.AbstractWebAppContextLoader.contextInitialized(AbstractWebAppContextLoader.java:85) ~[cuba-global-7.0-SNAPSHOT.jar:7.0-SNAPSHOT]
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4627) [catalina.jar:9.0.8]
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5091) [catalina.jar:9.0.8]

Googling around I read that EclipseLink does not allow the primary key to be modified programmaticaly and that could be the source of the problem (BaseUuidEntity sets the id on the constructor)… though it does not look so as any BaseUuidEntity I have works perfectly.

Regardless I tried:

@Entity(name = "metai4_ExtUser")
@UuidGenerator(name="USER_ID_GEN")
@Extends(User.class)
public class ExtUser extends User {
    @Column(name = "GOOGLE_ID", unique = true)
    protected String googleId;

    @Id
    @GeneratedValue(generator="USER_ID_GEN")
    @Column(name = "ID")
    protected UUID id;

    public ExtUser() {
    }

    public String getGoogleId() {
        return googleId;
    }

    public void setGoogleId(String googleId) {
        this.googleId = googleId;
    }

}

Still same exception raised :frowning:

Could you provide sample project with your error?

Hi,

I used your (@subbotin’s) sample70.zip project from another thread and to it I did:

  • Add the ExtUser class
  • Add Groovy Support (project properties, enable groovy)

The first step breaks nothing, but when I enable Groovy and start the server then things break.

The zip file contains my app.log for reference. I just deleted the deploy/ directory and run gradlew clean to make the zip smaller.

extuserSample.zip (429.8 KB)

We have created an issue: Entity model isn't enhanced with enabled groovy support · Issue #80 · cuba-platform/cuba-gradle-plugin · GitHub. It’s depends on the groovy support.

1 Like

The same issue happens now in latest version 7.0.3, please see Entity model isn't enhanced with enabled groovy support · Issue #80 · cuba-platform/cuba-gradle-plugin · GitHub

@tsarev told me that my reported issue is not related to Entity model isn't enhanced with enabled groovy support · Issue #80 · cuba-platform/cuba-gradle-plugin · GitHub, therefore, I’ll raise a new topic.