JPA CascadeType持续不起作用

时间:2016-10-19 10:32:24

标签: java jpa cascade

我有一个相当简单的设置,我有一个UserEntity和一个相应的UserStatisticEntity。我希望这是一个单向关系,UserEntity保存引用。应该使用UserEntity保留和删除UserStatisticEntity,因为我使用CascadeType.PERSIST和REMOVE。我正在使用Glassfish4和Eclipselink。目前我是这样做的:
UserEntity:

@Entity
public class UserEntity extends AdditionalEntityInformation {
@Id
@SequenceGenerator(name="seqGenUserId")
@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="seqGenUserId")
private long userId;
@OneToOne(cascade={CascadeType.PERSIST, CascadeType.REMOVE})
@JoinColumn(name="STAT_ID", unique=true, nullable=false, updatable=false, insertable=false)
@Basic(optional=false)
@Column(nullable=false)
private UserStatisticEntity stats;
...
public UserEntity(String username, String passwordHash, UserStatisticEntity stats) {
        this.username = username;
        this.passwordHash = passwordHash;
        this.stats = stats;
        this.loggedIn = false;
    }
}

UserStatisticEntity:

@Entity
public class UserStatisticEntity extends StatisticEntity {
private static final long serialVersionUID = 1L;

@Basic(fetch=FetchType.EAGER, optional=true)
private Date lastLogin;
}

不幸的是,这不起作用,当我坚持UserEntity时,相应的UserStatisticEntity不会被保留。
我错过了什么?(它可能非常简单明了,但对于我的生活,我没有看到它)

编辑: 下面的表是从类(重要的东西)创建的:
UserEntity:

USERID bigint(20)
STATS longblob

UserStatisticEntity:

ID bigint(20)
LASTLOGIN datetime

以下代码用于创建两个实体并保留它们。

UserStatisticEntity stats = new UserStatisticEntity(0, 0, 0, null);
UserEntity u = new UserEntity(username, hashingBean.hashString(password), stats);
em.persist(u);

UserEntity的持久性有效,但持久性不会级联到UserStatisticEntity。
我的日志记录:

2016-10-19T13:00:00.925+0200|Konfiguration: The access type for the persistent class [class de.fh_dortmund.hansen.chat.entity.AdditionalEntityInformation] is set to [FIELD].
2016-10-19T13:00:00.935+0200|Konfiguration: The access type for the persistent class [class de.fh_dortmund.hansen.chat.entity.UserEntity] is set to [FIELD].
2016-10-19T13:00:00.936+0200|Konfiguration: The access type for the persistent class [class de.fh_dortmund.hansen.chat.entity.StatisticEntity] is set to [FIELD].
2016-10-19T13:00:00.937+0200|Konfiguration: The access type for the persistent class [class de.fh_dortmund.hansen.chat.entity.UserStatisticEntity] is set to [FIELD].
2016-10-19T13:00:00.937+0200|Konfiguration: The access type for the persistent class [class de.fh_dortmund.hansen.chat.entity.CommonStatisticEntity] is set to [FIELD].
2016-10-19T13:00:00.940+0200|Konfiguration: The column name for element [createdAt] is being defaulted to: CREATEDAT.
2016-10-19T13:00:00.942+0200|Konfiguration: The column name for element [updatedAt] is being defaulted to: UPDATEDAT.
2016-10-19T13:00:00.942+0200|Konfiguration: The alias name for the entity class [class de.fh_dortmund.hansen.chat.entity.UserEntity] is being defaulted to: UserEntity.
2016-10-19T13:00:00.942+0200|Konfiguration: The table name for entity [class de.fh_dortmund.hansen.chat.entity.UserEntity] is being defaulted to: USERENTITY.
2016-10-19T13:00:00.946+0200|Konfiguration: The column name for element [createdAt] is being defaulted to: CREATEDAT.
2016-10-19T13:00:00.947+0200|Konfiguration: The column name for element [stats] is being defaulted to: STATS.
2016-10-19T13:00:00.948+0200|Konfiguration: The column name for element [loggedIn] is being defaulted to: LOGGEDIN.
2016-10-19T13:00:00.948+0200|Konfiguration: The column name for element [userId] is being defaulted to: USERID.
2016-10-19T13:00:00.948+0200|Konfiguration: The column name for element [passwordHash] is being defaulted to: PASSWORDHASH.
2016-10-19T13:00:00.949+0200|Konfiguration: The column name for element [username] is being defaulted to: USERNAME.
2016-10-19T13:00:00.949+0200|Konfiguration: The column name for element [updatedAt] is being defaulted to: UPDATEDAT.
2016-10-19T13:00:00.949+0200|Konfiguration: The alias name for the entity class [class de.fh_dortmund.hansen.chat.entity.UserStatisticEntity] is being defaulted to: UserStatisticEntity.
2016-10-19T13:00:00.950+0200|Konfiguration: The alias name for the entity class [class de.fh_dortmund.hansen.chat.entity.StatisticEntity] is being defaulted to: StatisticEntity.
2016-10-19T13:00:00.950+0200|Konfiguration: The table name for entity [class de.fh_dortmund.hansen.chat.entity.StatisticEntity] is being defaulted to: STATISTICENTITY.
2016-10-19T13:00:00.950+0200|Konfiguration: The column name for element [createdAt] is being defaulted to: CREATEDAT.
2016-10-19T13:00:00.951+0200|Konfiguration: The column name for element [logouts] is being defaulted to: LOGOUTS.
2016-10-19T13:00:00.951+0200|Konfiguration: The column name for element [messages] is being defaulted to: MESSAGES.
2016-10-19T13:00:00.951+0200|Konfiguration: The column name for element [id] is being defaulted to: ID.
2016-10-19T13:00:00.952+0200|Konfiguration: The column name for element [logins] is being defaulted to: LOGINS.
2016-10-19T13:00:00.952+0200|Konfiguration: The column name for element [updatedAt] is being defaulted to: UPDATEDAT.
2016-10-19T13:00:00.952+0200|Konfiguration: The table name for entity [class de.fh_dortmund.hansen.chat.entity.UserStatisticEntity] is being defaulted to: USERSTATISTICENTITY.
2016-10-19T13:00:00.952+0200|Konfiguration: The column name for element [lastLogin] is being defaulted to: LASTLOGIN.
2016-10-19T13:00:00.953+0200|Konfiguration: The column name for element [createdAt] is being defaulted to: CREATEDAT.
2016-10-19T13:00:00.953+0200|Konfiguration: The column name for element [logouts] is being defaulted to: LOGOUTS.
2016-10-19T13:00:00.954+0200|Konfiguration: The column name for element [messages] is being defaulted to: MESSAGES.
2016-10-19T13:00:00.954+0200|Konfiguration: The column name for element [id] is being defaulted to: ID.
2016-10-19T13:00:00.955+0200|Konfiguration: The column name for element [logins] is being defaulted to: LOGINS.
2016-10-19T13:00:00.956+0200|Konfiguration: The column name for element [updatedAt] is being defaulted to: UPDATEDAT.
2016-10-19T13:00:00.956+0200|Konfiguration: The alias name for the entity class [class de.fh_dortmund.hansen.chat.entity.CommonStatisticEntity] is being defaulted to: CommonStatisticEntity.
2016-10-19T13:00:00.956+0200|Konfiguration: The table name for entity [class de.fh_dortmund.hansen.chat.entity.CommonStatisticEntity] is being defaulted to: COMMONSTATISTICENTITY.
2016-10-19T13:00:00.956+0200|Konfiguration: The column name for element [createdAt] is being defaulted to: CREATEDAT.
2016-10-19T13:00:00.957+0200|Konfiguration: The column name for element [logouts] is being defaulted to: LOGOUTS.
2016-10-19T13:00:00.957+0200|Konfiguration: The column name for element [endDate] is being defaulted to: ENDDATE.
2016-10-19T13:00:00.957+0200|Konfiguration: The column name for element [messages] is being defaulted to: MESSAGES.
2016-10-19T13:00:00.957+0200|Konfiguration: The column name for element [id] is being defaulted to: ID.
2016-10-19T13:00:00.958+0200|Konfiguration: The column name for element [startingDate] is being defaulted to: STARTINGDATE.
2016-10-19T13:00:00.958+0200|Konfiguration: The column name for element [logins] is being defaulted to: LOGINS.
2016-10-19T13:00:00.958+0200|Konfiguration: The column name for element [updatedAt] is being defaulted to: UPDATEDAT.
2016-10-19T13:00:00.958+0200|Konfiguration: The sequence name for the sequence generator named [seqGenStatId] defined on [field id] from [field id] is being defaulted to: seqGenStatId.
2016-10-19T13:00:00.959+0200|Konfiguration: The sequence name for the sequence generator named [seqGenUserId] defined on [field userId] from [field userId] is being defaulted to: seqGenUserId.
2016-10-19T13:00:00.960+0200|Feiner: Class [de.fh_dortmund.hansen.chat.entity.UserEntity] registered to be processed by weaver.
2016-10-19T13:00:00.962+0200|Feiner: Class [de.fh_dortmund.hansen.chat.entity.UserStatisticEntity] registered to be processed by weaver.
2016-10-19T13:00:00.962+0200|Feiner: Class [de.fh_dortmund.hansen.chat.entity.StatisticEntity] registered to be processed by weaver.
2016-10-19T13:00:00.962+0200|Feiner: Class [de.fh_dortmund.hansen.chat.entity.CommonStatisticEntity] registered to be processed by weaver.
2016-10-19T13:00:01.027+0200|Am feinsten: End predeploying Persistence Unit ChatDB; session /file:/D:/glassfish4/glassfish/domains/domain1/eclipseApps/Chat-ear/Chat-ejb_jar/_ChatDB; state Predeployed; factoryCount 1
2016-10-19T13:00:01.032+0200|Feiner: Canonical Metamodel class [de.fh_dortmund.hansen.chat.entity.StatisticEntity_] not found during initialization.
2016-10-19T13:00:01.032+0200|Feiner: Canonical Metamodel class [de.fh_dortmund.hansen.chat.entity.CommonStatisticEntity_] not found during initialization.
2016-10-19T13:00:01.033+0200|Feiner: Canonical Metamodel class [de.fh_dortmund.hansen.chat.entity.UserEntity_] not found during initialization.
2016-10-19T13:00:01.033+0200|Feiner: Canonical Metamodel class [de.fh_dortmund.hansen.chat.entity.UserStatisticEntity_] not found during initialization.
2016-10-19T13:00:01.033+0200|Feiner: Canonical Metamodel class [de.fh_dortmund.hansen.chat.entity.AdditionalEntityInformation_] not found during initialization.
2016-10-19T13:00:01.370+0200|Am feinsten: Begin deploying Persistence Unit ChatDB; session /file:/D:/glassfish4/glassfish/domains/domain1/eclipseApps/Chat-ear/Chat-ejb_jar/_ChatDB; state Predeployed; factoryCount 1
2016-10-19T13:00:01.374+0200|Am feinsten: Begin weaver class transformer processing class [de/fh_dortmund/hansen/chat/entity/UserEntity].
2016-10-19T13:00:01.381+0200|Am feinsten: Weaved change tracking (ChangeTracker) [de/fh_dortmund/hansen/chat/entity/UserEntity].
2016-10-19T13:00:01.382+0200|Am feinsten: Weaved fetch groups (FetchGroupTracker) [de/fh_dortmund/hansen/chat/entity/UserEntity].
2016-10-19T13:00:01.382+0200|Am feinsten: End weaver class transformer processing class [de/fh_dortmund/hansen/chat/entity/UserEntity].
2016-10-19T13:00:01.382+0200|Information: de.fh_dortmund.hansen.chat.entity.UserEntity actually got transformed
2016-10-19T13:00:01.389+0200|Am feinsten: Begin weaver class transformer processing class [de/fh_dortmund/hansen/chat/entity/AdditionalEntityInformation].
2016-10-19T13:00:01.390+0200|Am feinsten: Weaved persistence (PersistenceEntity) [de/fh_dortmund/hansen/chat/entity/AdditionalEntityInformation].
2016-10-19T13:00:01.391+0200|Am feinsten: Weaved change tracking (ChangeTracker) [de/fh_dortmund/hansen/chat/entity/AdditionalEntityInformation].
2016-10-19T13:00:01.391+0200|Am feinsten: Weaved fetch groups (FetchGroupTracker) [de/fh_dortmund/hansen/chat/entity/AdditionalEntityInformation].
2016-10-19T13:00:01.391+0200|Am feinsten: Weaved REST [de/fh_dortmund/hansen/chat/entity/AdditionalEntityInformation].
2016-10-19T13:00:01.391+0200|Am feinsten: End weaver class transformer processing class [de/fh_dortmund/hansen/chat/entity/AdditionalEntityInformation].
2016-10-19T13:00:01.391+0200|Information: de.fh_dortmund.hansen.chat.entity.AdditionalEntityInformation actually got transformed
2016-10-19T13:00:01.400+0200|Am feinsten: Begin weaver class transformer processing class [de/fh_dortmund/hansen/chat/entity/UserStatisticEntity].
2016-10-19T13:00:01.401+0200|Am feinsten: Weaved change tracking (ChangeTracker) [de/fh_dortmund/hansen/chat/entity/UserStatisticEntity].
2016-10-19T13:00:01.401+0200|Am feinsten: Weaved fetch groups (FetchGroupTracker) [de/fh_dortmund/hansen/chat/entity/UserStatisticEntity].
2016-10-19T13:00:01.401+0200|Am feinsten: End weaver class transformer processing class [de/fh_dortmund/hansen/chat/entity/UserStatisticEntity].
2016-10-19T13:00:01.401+0200|Information: de.fh_dortmund.hansen.chat.entity.UserStatisticEntity actually got transformed
2016-10-19T13:00:01.402+0200|Am feinsten: Begin weaver class transformer processing class [de/fh_dortmund/hansen/chat/entity/StatisticEntity].
2016-10-19T13:00:01.403+0200|Am feinsten: Weaved change tracking (ChangeTracker) [de/fh_dortmund/hansen/chat/entity/StatisticEntity].
2016-10-19T13:00:01.404+0200|Am feinsten: Weaved fetch groups (FetchGroupTracker) [de/fh_dortmund/hansen/chat/entity/StatisticEntity].
2016-10-19T13:00:01.404+0200|Am feinsten: End weaver class transformer processing class [de/fh_dortmund/hansen/chat/entity/StatisticEntity].
2016-10-19T13:00:01.405+0200|Information: de.fh_dortmund.hansen.chat.entity.StatisticEntity actually got transformed
2016-10-19T13:00:01.420+0200|Am feinsten: Begin weaver class transformer processing class [de/fh_dortmund/hansen/chat/entity/CommonStatisticEntity].
2016-10-19T13:00:01.422+0200|Am feinsten: Weaved change tracking (ChangeTracker) [de/fh_dortmund/hansen/chat/entity/CommonStatisticEntity].
2016-10-19T13:00:01.422+0200|Am feinsten: Weaved fetch groups (FetchGroupTracker) [de/fh_dortmund/hansen/chat/entity/CommonStatisticEntity].
2016-10-19T13:00:01.423+0200|Am feinsten: End weaver class transformer processing class [de/fh_dortmund/hansen/chat/entity/CommonStatisticEntity].
2016-10-19T13:00:01.423+0200|Information: de.fh_dortmund.hansen.chat.entity.CommonStatisticEntity actually got transformed
2016-10-19T13:00:01.449+0200|Feiner: initializing session manager
2016-10-19T13:00:01.451+0200|Am feinsten: property=eclipselink.target-server; value=SunAS9; translated value=org.eclipse.persistence.platform.server.sunas.SunAS9ServerPlatform
2016-10-19T13:00:01.451+0200|Am feinsten: property=eclipselink.logging.level; value=FINEST; translated value=FINEST
2016-10-19T13:00:01.452+0200|Am feinsten: property=eclipselink.logging.level; value=FINEST; translated value=FINEST
2016-10-19T13:00:01.452+0200|Am feinsten: property=eclipselink.target-database; value=MySQL; translated value=org.eclipse.persistence.platform.database.MySQLPlatform
2016-10-19T13:00:01.465+0200|Information: EclipseLink, version: Eclipse Persistence Services - 2.6.1.v20150605-31e8258
2016-10-19T13:00:01.470+0200|Konfiguration: connecting(DatabaseLogin(
    platform=>MySQLPlatform
    user name=> ""
    connector=>JNDIConnector datasource name=>null
))
2016-10-19T13:00:01.922+0200|Konfiguration: Connected: jdbc:mysql://localhost:3306/chat
    User: chat@localhost
    Database: MySQL  Version: 5.7.16-log
    Driver: MySQL Connector Java  Version: mysql-connector-java-5.1.40 ( Revision: 402933ef52cad9aa82624e80acbea46e3a701ce6 )
2016-10-19T13:00:01.922+0200|Am feinsten: Connection acquired from connection pool [read].
2016-10-19T13:00:01.922+0200|Am feinsten: Connection released to connection pool [read].
2016-10-19T13:00:01.922+0200|Konfiguration: connecting(DatabaseLogin(
    platform=>MySQLPlatform
    user name=> ""
    connector=>JNDIConnector datasource name=>null
))
2016-10-19T13:00:01.923+0200|Konfiguration: Connected: jdbc:mysql://localhost:3306/chat
    User: chat@localhost
    Database: MySQL  Version: 5.7.16-log
    Driver: MySQL Connector Java  Version: mysql-connector-java-5.1.40 ( Revision: 402933ef52cad9aa82624e80acbea46e3a701ce6 )
2016-10-19T13:00:01.929+0200|Am feinsten: sequencing connected, state is NoPreallocation_State
2016-10-19T13:00:01.930+0200|Am feinsten: sequence seqGenStatId: preallocation size 50
2016-10-19T13:00:01.930+0200|Am feinsten: sequence seqGenUserId: preallocation size 50
2016-10-19T13:00:02.000+0200|Information: /file:/D:/glassfish4/glassfish/domains/domain1/eclipseApps/Chat-ear/Chat-ejb_jar/_ChatDB login successful
2016-10-19T13:00:02.000+0200|Feiner: JMX MBeanServer instance found: [com.sun.enterprise.v3.admin.DynamicInterceptor@897b71], # of beans: [24], domain: [DefaultDomain] at index: [0].
2016-10-19T13:00:02.002+0200|Am feinsten: Registered MBean: org.eclipse.persistence.services.mbean.MBeanDevelopmentServices[TopLink:Name=Development-/file_/D_/glassfish4/glassfish/domains/domain1/eclipseApps/Chat-ear/Chat-ejb_jar/_ChatDB,Type=Configuration] on server com.sun.enterprise.v3.admin.DynamicInterceptor@897b71
2016-10-19T13:00:02.003+0200|Am feinsten: Registered MBean: org.eclipse.persistence.services.glassfish.MBeanGlassfishRuntimeServices[TopLink:Name=Session(/file_/D_/glassfish4/glassfish/domains/domain1/eclipseApps/Chat-ear/Chat-ejb_jar/_ChatDB)] on server com.sun.enterprise.v3.admin.DynamicInterceptor@897b71
2016-10-19T13:00:02.003+0200|Am feinsten: EclipseLink JMX Runtime Services is referencing the [Platform ConversionManager] ClassLoader at: [EarClassLoader : 
urlSet = [URLEntry : file:/D:/glassfish4/glassfish/domains/domain1/eclipseApps/Chat-ear/Chat-ejb_jar/, URLEntry : file:/D:/glassfish4/glassfish/domains/domain1/generated/ejb/Chat-ear/Chat-ejb_jar, URLEntry : file:/D:/glassfish4/glassfish/domains/domain1/eclipseApps/Chat-ear/Chat-common.jar/]
doneCalled = false 
 Parent -> org.glassfish.internal.api.DelegatingClassLoader@73b5a73d
]
2016-10-19T13:00:02.003+0200|Am feinsten: The applicationName for the MBean attached to session [/file:/D:/glassfish4/glassfish/domains/domain1/eclipseApps/Chat-ear/Chat-ejb_jar/_ChatDB] is [D:/glassfish4/glassfish/domains/domain1/eclipseApps/Chat-ear/Chat-ejb_jar/_URLEntry _file:/D:/glassfish4/glassfish/domains/domain1/generated/ejb/Chat-ear/Chat-ejb_jar_URLEntry _file:/D:/glassfish4/glassfish/domains/domain1/eclipseApps/Chat-ear/Chat-common.jar/]
2016-10-19T13:00:02.003+0200|Am feinsten: The moduleName for the MBean attached to session [/file:/D:/glassfish4/glassfish/domains/domain1/eclipseApps/Chat-ear/Chat-ejb_jar/_ChatDB] is [_ChatDB]
2016-10-19T13:00:02.015+0200|Am feinsten: The table (COMMONSTATISTICENTITY) is created.
2016-10-19T13:00:02.016+0200|Am feinsten: The table (USERENTITY) is created.
2016-10-19T13:00:02.016+0200|Am feinsten: The table (USERSTATISTICENTITY) is created.
2016-10-19T13:00:02.018+0200|Feiner: Canonical Metamodel class [de.fh_dortmund.hansen.chat.entity.StatisticEntity_] not found during initialization.
2016-10-19T13:00:02.019+0200|Feiner: Canonical Metamodel class [de.fh_dortmund.hansen.chat.entity.CommonStatisticEntity_] not found during initialization.
2016-10-19T13:00:02.020+0200|Feiner: Canonical Metamodel class [de.fh_dortmund.hansen.chat.entity.UserEntity_] not found during initialization.
2016-10-19T13:00:02.021+0200|Feiner: Canonical Metamodel class [de.fh_dortmund.hansen.chat.entity.UserStatisticEntity_] not found during initialization.
2016-10-19T13:00:02.022+0200|Feiner: Canonical Metamodel class [de.fh_dortmund.hansen.chat.entity.AdditionalEntityInformation_] not found during initialization.
2016-10-19T13:00:02.022+0200|Am feinsten: End deploying Persistence Unit ChatDB; session /file:/D:/glassfish4/glassfish/domains/domain1/eclipseApps/Chat-ear/Chat-ejb_jar/_ChatDB; state Deployed; factoryCount 1
2016-10-19T13:00:09.314+0200|Fein: SELECT COUNT(USERID) FROM USERENTITY WHERE (USERNAME = ?)
    bind => [1 parameter bound]
2016-10-19T13:00:09.333+0200|Am feinsten: Connection released to connection pool [read].
2016-10-19T13:00:09.335+0200|Am feinsten: persist() operation called on: de.fh_dortmund.hansen.chat.entity.CommonStatisticEntity@2a0f113c.
2016-10-19T13:00:09.397+0200|Feiner: begin unit of work flush
2016-10-19T13:00:09.397+0200|Feiner: TX beginTransaction, status=STATUS_ACTIVE
2016-10-19T13:00:09.398+0200|Am feinsten: Execute query InsertObjectQuery(de.fh_dortmund.hansen.chat.entity.CommonStatisticEntity@2a0f113c)
2016-10-19T13:00:09.398+0200|Am feinsten: Connection acquired from connection pool [default].
2016-10-19T13:00:09.398+0200|Am feinsten: reconnecting to external connection pool
2016-10-19T13:00:09.399+0200|Fein: INSERT INTO COMMONSTATISTICENTITY (CREATEDAT, ENDDATE, LOGINS, LOGOUTS, MESSAGES, STARTINGDATE, UPDATEDAT) VALUES (?, ?, ?, ?, ?, ?, ?)
    bind => [7 parameters bound]
2016-10-19T13:00:09.405+0200|Am feinsten: Execute query ValueReadQuery(name="seqGenStatId" sql="SELECT LAST_INSERT_ID()")
2016-10-19T13:00:09.405+0200|Fein: SELECT LAST_INSERT_ID()
2016-10-19T13:00:09.406+0200|Am feinsten: assign sequence to the object (1 -> de.fh_dortmund.hansen.chat.entity.CommonStatisticEntity@2a0f113c)
2016-10-19T13:00:09.407+0200|Feiner: end unit of work flush
2016-10-19T13:00:09.408+0200|Feiner: resume unit of work
2016-10-19T13:00:09.408+0200|Am feinsten: Execute query ReportQuery(name="getNumUsersWithName" referenceClass=UserEntity sql="SELECT COUNT(USERID) FROM USERENTITY WHERE (USERNAME = ?)")
2016-10-19T13:00:09.409+0200|Fein: SELECT COUNT(USERID) FROM USERENTITY WHERE (USERNAME = ?)
    bind => [1 parameter bound]
2016-10-19T13:00:09.412+0200|Am feinsten: persist() operation called on: de.fh_dortmund.hansen.chat.entity.UserEntity@b49eec8.
2016-10-19T13:00:09.421+0200|Feiner: TX beforeCompletion callback, status=STATUS_ACTIVE
2016-10-19T13:00:09.421+0200|Feiner: begin unit of work commit
2016-10-19T13:00:09.422+0200|Am feinsten: Execute query InsertObjectQuery(de.fh_dortmund.hansen.chat.entity.UserEntity@b49eec8)
2016-10-19T13:00:09.423+0200|Fein: INSERT INTO USERENTITY (CREATEDAT, LOGGEDIN, PASSWORDHASH, STATS, UPDATEDAT, USERNAME) VALUES (?, ?, ?, ?, ?, ?)
    bind => [6 parameters bound]
2016-10-19T13:00:09.425+0200|Am feinsten: Execute query ValueReadQuery(name="seqGenUserId" sql="SELECT LAST_INSERT_ID()")
2016-10-19T13:00:09.425+0200|Fein: SELECT LAST_INSERT_ID()
2016-10-19T13:00:09.426+0200|Am feinsten: assign sequence to the object (1 -> de.fh_dortmund.hansen.chat.entity.UserEntity@b49eec8)
2016-10-19T13:00:09.431+0200|Am feinsten: Connection released to connection pool [default].

EDIT2:UserStatisticEntity可以通过继承进行序列化,如果我删除了这个序列可靠性,我的ejb部署就会出现这个错误:

Exception Description: The type [class de.fh_dortmund.hansen.chat.entity.UserStatisticEntity] for the attribute [stats] on the entity class [class de.fh_dortmund.hansen.chat.entity.UserEntity] is not a valid type for a serialized mapping. The attribute type must implement the Serializable interface.

1 个答案:

答案 0 :(得分:1)

我认为解决方案非常简单。出于某种原因,Eclipselink真的很烦恼,因为一个UserStatisticEntity是可序列化的,并且我在stats字段上有所有这些注释。在使其不可序列化然后删除@Basic和@Column注释后,以下代码可以正常工作:

@OneToOne(cascade={CascadeType.PERSIST, CascadeType.REMOVE})
@JoinColumn(nullable=false,unique=true)
private UserStatisticEntity stats;