gpt4 book ai didi

java - 非法参数异常 : expecting IdClass mapping

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:43:50 25 4
gpt4 key购买 nike

在部署我的应用程序期间,我遇到了那个异常。我的应用程序中有很多类,但我不知道必须在哪里放置 @IdClass 以及这个异常到底意味着什么。我正在使用 Hibernate 4.1 和 JBoss AS 7.1

12:10:23,761 INFO  [org.hibernate.engine.jdbc.internal.LobCreatorBuilder] (MSC service thread 1-5) HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
12:10:24,075 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] (MSC service thread 1-5) HHH000389: Unsuccessful: drop sequence hibernate_sequence
12:10:24,076 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] (MSC service thread 1-5) ERROR: sequence "hibernate_sequence" does not exist
12:10:24,281 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-5) MSC00001: Failed to start service jboss.persistenceunit."kladr.ear/kladr-ejb-1.0-SNAPSHOT.jar#primary": org.jboss.msc.service.StartException in service jboss.persistenceunit."kladr.ear/kladr-ejb-1.0-SNAPSHOT.jar#primary": Failed to start service
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1767) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_35]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_35]
at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_35]
Caused by: java.lang.IllegalArgumentException: expecting IdClass mapping
at org.hibernate.ejb.metamodel.AttributeFactory$3.resolveMember(AttributeFactory.java:878)
at org.hibernate.ejb.metamodel.AttributeFactory$4.resolveMember(AttributeFactory.java:915)
at org.hibernate.ejb.metamodel.AttributeFactory.determineAttributeMetadata(AttributeFactory.java:423)
at org.hibernate.ejb.metamodel.AttributeFactory.buildAttribute(AttributeFactory.java:91)
at org.hibernate.ejb.metamodel.MetadataContext.wrapUp(MetadataContext.java:214)
at org.hibernate.ejb.metamodel.MetamodelImpl.buildMetamodel(MetamodelImpl.java:64)
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:91)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:889)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:162)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.start(PersistenceUnitServiceImpl.java:85)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
... 3 more

最佳答案

@IdClass注解用于定义包含id的Class。即,这通常用于定义复合键的情况。即多个属性的关键组合。如果是这样,那我们就是这样做的。看看下面的例子..我们定义一个类作为 IdClass 并使用 @Id 为这个IdClass 定义各种 Id .



示例:



@Entity
@IdClass(AssignedRoleId.class)
public class AssignedRole
{
@Id
@ManyToOne
private User userId;

@Id
@ManyToOne
private Role roleId;

private Date dateAssigned;
}

希望这对您有所帮助。

关于java - 非法参数异常 : expecting IdClass mapping,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12930935/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com