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:
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;
}
}