本文介绍了如何创建一个复合主键休眠JPA?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我尝试使用hibernate JPA从2个外键创建表中的复合主键,但是却给我带来了错误。我找到了一些解决方案,但没有任何内容 表格之间的关系如下所示: 表格客户 clientID(PK) 名字 姓氏。 表CarService serviceID(PK) DescriptionOfFailure 。 。 表ServiceDepartment clientID(PK) serviceID(PK)价格。 执行我的代码如下所示: @Entity public class ServiceDepartmentBean实现ServiceDepartmentI { @EmbeddedId private ServiceDepartmentPK serviceDepartmentPK = new ServiceDepartmentPK(); @Column(name =clientID,nullable = false,updatable = false,insertable = false) private长客户端; @Column(name =serviceId,nullable = false,updatable = false,insertable = false)私人长期服务; @Column 私人双重价格; 。 。 。 。 public void setClient(ClientI client){ serviceDepartmentPK.setClient(client); } public void setService(CarServiceI service){ serviceDepartmentPK.setService(service); public ClientI getClient(){ return serviceDepartmentPK.getClient(); } public CarServiceI getService(){ return serviceDepartmentPK.getService(); } @Entity 公共类CarServiceBean实现CarServiceI { @Id @GeneratedValue private long serviceId; @Column(nullable = false) private String descriptionOfFailure; @OneToMany(mappedBy =service) private List< ServiceDepartmentI> servicesDepartments; public List< ServiceDepartmentI> getServicesDepartments(){ return servicesDepartments; } 。 。 //设置我的方法 @Entity 公共类ClientBean实现ClientI { @Id @GeneratedValue 私有长客户端ID; @Column(nullable = false) private String firstName; @Column(nullable = false) private String lastName; @OneToMany(mappedBy =client) private List< ServiceDepartmentI> servicesDepartments; public void setServicesDepartments(List< ServiceDepartmentI> servicesDepartments){ this.servicesDepartments = servicesDepartments; } public List< ServiceDepartmentI> getServicesDepartments(){ return servicesDepartments; public class ServiceDepartmentPK实现Serializable { @ManyToOne 私有ClientI客户端; @ManyToOne 私人CarServiceI服务; public void setClient(ClientI client){ this.client = client; } public ClientI getClient(){ return client; } public void setService(CarServiceI service){ this.service = service; } public CarServiceI getService(){ return service; 当尝试构建apllication时,会在控制台中引发错误: stacktrace: [INFO] annotations.EntityBinder在表ServiceDepartmentBean上绑定实体com.fit.beans.ServiceDepartmentBean [错误] ioc.Registry错误调用构造函数public org.apache.tapestry5.internal.hibernate.HibernateSessionSourceImpl(org.slf4j.Logger,java.util.List):java.lang.NullPointerException [错误] ioc.Registry操作跟踪: [错误] ioc.Registry [1]实现服务HibernateSessionSource [错误] ioc.Registry [2]通过org.apache.tapestry5.internal.hibernate实例化服务HibernateSessionSource实现。 HibernateSessionSourceImpl(Logger,List)(在HibernateSessionSourceImpl.java:36)通过org.apache.tapestry5.hibernate.HibernateCoreModule.bind(ServiceBinder)(在HibernateCoreModule.java:45) [错误] ioc.Registry [3]调用构造函数org.apache.tapestry5.internal.hibernate.Hibernate SessionSourceImpl(Logger,List)(在HibernateSessionSourceImpl.java:36)通过org.apache.tapestry5.hibernate.HibernateCoreModule.bind(ServiceBinder)(在HibernateCoreModule.java:45)(用于服务'HibernateSessionSource') [ERROR ] HibernateCoreModule.HibernateSessionSource服务构造HibernateSessionSource失败:错误调用构造函数public org.apache.tapestry5.internal.hibernate.HibernateSessionSourceImpl(org.slf4j.Logger,java.util.List):java.lang.NullPointerException org。 apache.tapestry5.ioc.internal.OperationException:错误调用构造函数公共org.apache.tapestry5.internal.hibernate.HibernateSessionSourceImpl(org.slf4j.Logger,java.util.List中):显示java.lang.NullPointerException 。在组织.apache.tapestry5.ioc.internal.OperationTrackerImpl.logAndRethrow(OperationTrackerImpl.java:121)在org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:88)。在组织.apache.tapestry5.ioc.internal.PerThreadOper ationTracker.invoke(PerThreadOperationTracker.java:87)位于org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1121)位于org.apache.tapestry5.ioc.internal。 util.ConstructionPlan.createObject(ConstructionPlan.java:60)在org.apache.tapestry5.ioc.internal.ConstructorServiceCreator.createObject(ConstructorServiceCreator.java:61)在org.apache.tapestry5.ioc。 internal.OperationTrackingObjectCreator $ 1.invoke(OperationTrackingObjectCreator.java:45)在org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:74) 在org.apache.tapestry5.ioc .internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:87) at org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1121) 任何帮助都会被赞赏=) 重构后的新错误stacktrace: [INFO] cfg.AnnotationBin der注释类中的绑定实体:com.fit.beans.CarServiceBean [INFO] annotations.EntityBinder在表CarServiceBean上绑定实体com.fit.beans.CarServiceBean [INFO] cfg.AnnotationBinder注释中的绑定实体类:com.fit.beans.ServiceDepartmentBean [INFO] annotations.EntityBinder绑定实体com.fit.beans.ServiceDepartmentBean上表ServiceDepartmentBean [错误] ioc.Registry错误调用构造函数公共org.apache.tapestry5 .internal.hibernate.HibernateSessionSourceImpl(org.slf4j.Logger,java.util.List):没有为实体指定标识符:com.fit.beans.ServiceDepartmentBean [错误] ioc.Registry操作跟踪: [错误] ioc.Registry [1]实现服务HibernateSessionSource [错误] ioc.Registry [2]通过org.apache.tapestry5.internal.hibernate.HibernateSessionSourceImpl(Logger,List)实例化服务HibernateSessionSource实现(在HibernateSessionSourceImpl。 java:36)通过org.apache.tapestry5.hibernate.Hibern ateCoreModule.bind(ServiceBinder)(在HibernateCoreModule.java:45) [错误] ioc.Registry [3]调用构造函数org.apache.tapestry5.internal.hibernate.HibernateSessionSourceImpl(Logger,List)(在HibernateSessionSourceImpl.java :36)通过org.apache.tapestry5.hibernate.HibernateCoreModule.bind(ServiceBinder)(在HibernateCoreModule.java:45)(用于服务'HibernateSessionSource') [错误] HibernateCoreModule.HibernateSessionSource服务构造HibernateSessionSource失败:错误调用构造函数public org.apache.tapestry5.internal.hibernate.HibernateSessionSourceImpl(org.slf4j.Logger,java.util.List):没有为实体指定标识符:com.fit.beans.ServiceDepartmentBean org.apache.tapestry5 .ioc.internal.OperationException:调用构造函数的错误public org.apache.tapestry5.internal.hibernate.HibernateSessionSourceImpl(org.slf4j.Logger,java.util.List):没有为实体指定标识符:com.fit.beans.ServiceDepartmentBean 在org.apache.ta pestry5.ioc.internal.OperationTrackerImpl.logAndRethrow(OperationTrackerImpl.java:121)处org.apache org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:88)。 tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:87)在org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1121)在org.apache。 tapestry5.ioc.internal.util.ConstructionPlan.createObject(ConstructionPlan.java:60) at org.apache.tapestry5.ioc.internal.ConstructorServiceCreator.createObject(ConstructorServiceCreator.java:61) at org。 apache.tapestry5.ioc.internal.OperationTrackingObjectCreator $ 1.invoke(OperationTrackingObjectCreator.java:45)在org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:74) 。在组织.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:87) at org.apache.tapestry5.i oc.internal.RegistryImpl.invoke(RegistryImpl.java:1121) at org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator.createObject(OperationTrackingObjectCreator.java:49) at org.apache.tapestry5。 ioc.internal.SingletonServiceLifecycle.createService(SingletonServiceLifecycle.java:29) at org.apache.tapestry5.ioc.internal.LifecycleWrappedServiceCreator.createObject(LifecycleWrappedServiceCreator.java:46) at org.apache.tapestry5。 ioc.internal.AdvisorStackBuilder.createObject(AdvisorStackBuilder.java:63)位于org.apache.tapestry5.ioc.internal.InterceptorStackBuilder.createObject(InterceptorStackBuilder.java:54)位于org.apache.tapestry5。 ioc.internal.RecursiveServiceCreationCheckWrapper.createObject(RecursiveServiceCreationCheckWrapper.java:60) at org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator $ 1.invoke(OperationTrackingObjectCreator.java:45) at org.apache.tapestry5 .ioc.internal.OperationTrackerImpl.invo ke(OperationTrackerImpl.java:74)在org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:87)。 。 。 。 。 导致:java.lang.RuntimeException:调用构造函数的错误public org.apache.tapestry5.internal.hibernate.HibernateSessionSourceImpl(org.slf4j.Logger,java.util.List):没有为entity:com指定标识符。在org.apache.tapestry5.ioc.internal.util.ConstructorInvoker.invoke(ConstructorInvoker.java:57)上的fit.beans.ServiceDepartmentBean .invoke(LoggingInvokableWrapper.java:42) at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:74) ... 72 more 引起: org.hibernate.AnnotationException:没有为实体指定标识符:com.fit.beans.ServiceDepartmentBean 在org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:672)在org.hibernate.cfg .AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:546) at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConf org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1333) org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867) $ b $ $ b at org.apache.tapestry5.internal.hibernate.HibernateSessionSourceImpl。< init>(HibernateSessionSourceImpl.java:46) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)$ b $ sun at.reflect .NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513 ) at org.apache.tapestry5.ioc.internal.util.ConstructorInvoker.invoke(ConstructorInvoker.java:48) ... 74 more 解决方案从中移除构造函数 @EmbeddedId private ServiceDe partmentPK serviceDepartmentPK; 从ServiceDepartmentPK类中删除@ManyToOne注释并将字段类型设置为long或int @Embeddable 公共类ServiceDepartmentPK实现Serializable { private static final long serialVersionUID = 1L; @Column(name =COLUMN_NAME) private long clientId; @Column(name =COLUMN_NAME) private carServiceId; public ServiceDepartmentPK(){} //客户端和服务器的getters设置器ids -s public boolean equals(Object other){ if(this == other){ return true; } if(!(other ServiceofPackagingPK)){ return false; } ServiceDepartmentPK castOther =(ServiceDepartmentPK)other; 返回(this.scopeId == castOther.clientId)&& (this.scriptId == castOther.carServiceId); public int hashCode(){ final int prime = 31; int hash = 17; hash = hash * prime +((int)(this.clientId ^(this.clientId>>> 32))); hash = hash * prime +((int)(this.carServiceId ^(this.carServiceId>>>> 32))); 返回散列; } } i try to create composite primary key in table from 2 foreign key using hibernate JPA,but gives me error.I find some solution on net but nothingThe relations between tables looks like this: Table Client clientID(PK) FirstName LastName . Table CarService serviceID(PK) DescriptionOfFailure..Table ServiceDepartmentclientID(PK)serviceID(PK)price.implementation of my code looks like this:@Entitypublic class ServiceDepartmentBean implements ServiceDepartmentI { @EmbeddedId private ServiceDepartmentPK serviceDepartmentPK = new ServiceDepartmentPK(); @Column(name="clientID", nullable=false, updatable=false, insertable=false) private Long client; @Column(name="serviceId", nullable=false, updatable=false, insertable=false) private Long service; @Column private double price; . . . . public void setClient(ClientI client){ serviceDepartmentPK.setClient(client); } public void setService(CarServiceI service){ serviceDepartmentPK.setService(service); } public ClientI getClient(){ return serviceDepartmentPK.getClient(); } public CarServiceI getService(){ return serviceDepartmentPK.getService(); }@Entitypublic class CarServiceBean implements CarServiceI { @Id @GeneratedValue private long serviceId; @Column(nullable = false) private String descriptionOfFailure; @OneToMany(mappedBy="service")private List<ServiceDepartmentI> servicesDepartments;public List<ServiceDepartmentI> getServicesDepartments() { return servicesDepartments;} . . //set i get method@Entitypublic class ClientBean implements ClientI { @Id @GeneratedValue private long clientID; @Column(nullable = false) private String firstName; @Column(nullable = false) private String lastName; @OneToMany(mappedBy = "client")private List<ServiceDepartmentI> servicesDepartments;public void setServicesDepartments(List<ServiceDepartmentI> servicesDepartments) { this.servicesDepartments = servicesDepartments;}public List<ServiceDepartmentI> getServicesDepartments() { return servicesDepartments;}}public class ServiceDepartmentPK implements Serializable { @ManyToOne private ClientI client; @ManyToOne private CarServiceI service; public void setClient(ClientI client) { this.client = client; } public ClientI getClient() { return client; } public void setService(CarServiceI service) { this.service = service; } public CarServiceI getService() { return service; }}when try to build apllication throws me a error in console:stacktrace:[INFO] annotations.EntityBinder Bind entity com.fit.beans.ServiceDepartmentBean on table ServiceDepartmentBean[ERROR] ioc.Registry Error invoking constructor public org.apache.tapestry5.internal.hibernate.HibernateSessionSourceImpl(org.slf4j.Logger,java.util.List): java.lang.NullPointerException[ERROR] ioc.Registry Operations trace:[ERROR] ioc.Registry [ 1] Realizing service HibernateSessionSource[ERROR] ioc.Registry [ 2] Instantiating service HibernateSessionSource implementation via org.apache.tapestry5.internal.hibernate.HibernateSessionSourceImpl(Logger, List) (at HibernateSessionSourceImpl.java:36) via org.apache.tapestry5.hibernate.HibernateCoreModule.bind(ServiceBinder) (at HibernateCoreModule.java:45)[ERROR] ioc.Registry [ 3] Invoking constructor org.apache.tapestry5.internal.hibernate.HibernateSessionSourceImpl(Logger, List) (at HibernateSessionSourceImpl.java:36) via org.apache.tapestry5.hibernate.HibernateCoreModule.bind(ServiceBinder) (at HibernateCoreModule.java:45) (for service 'HibernateSessionSource')[ERROR] HibernateCoreModule.HibernateSessionSource Construction of service HibernateSessionSource failed: Error invoking constructor public org.apache.tapestry5.internal.hibernate.HibernateSessionSourceImpl(org.slf4j.Logger,java.util.List): java.lang.NullPointerExceptionorg.apache.tapestry5.ioc.internal.OperationException: Error invoking constructor public org.apache.tapestry5.internal.hibernate.HibernateSessionSourceImpl(org.slf4j.Logger,java.util.List): java.lang.NullPointerException at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.logAndRethrow(OperationTrackerImpl.java:121) at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:88) at org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:87) at org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1121) at org.apache.tapestry5.ioc.internal.util.ConstructionPlan.createObject(ConstructionPlan.java:60) at org.apache.tapestry5.ioc.internal.ConstructorServiceCreator.createObject(ConstructorServiceCreator.java:61) at org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator$1.invoke(OperationTrackingObjectCreator.java:45) at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:74) at org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:87) at org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1121)Any help would be appreciated =)new error after refactoring stacktrace:[INFO] cfg.AnnotationBinder Binding entity from annotated class: com.fit.beans.CarServiceBean[INFO] annotations.EntityBinder Bind entity com.fit.beans.CarServiceBean on table CarServiceBean[INFO] cfg.AnnotationBinder Binding entity from annotated class: com.fit.beans.ServiceDepartmentBean[INFO] annotations.EntityBinder Bind entity com.fit.beans.ServiceDepartmentBean on table ServiceDepartmentBean[ERROR] ioc.Registry Error invoking constructor public org.apache.tapestry5.internal.hibernate.HibernateSessionSourceImpl(org.slf4j.Logger,java.util.List): No identifier specified for entity: com.fit.beans.ServiceDepartmentBean[ERROR] ioc.Registry Operations trace:[ERROR] ioc.Registry [ 1] Realizing service HibernateSessionSource[ERROR] ioc.Registry [ 2] Instantiating service HibernateSessionSource implementation via org.apache.tapestry5.internal.hibernate.HibernateSessionSourceImpl(Logger, List) (at HibernateSessionSourceImpl.java:36) via org.apache.tapestry5.hibernate.HibernateCoreModule.bind(ServiceBinder) (at HibernateCoreModule.java:45)[ERROR] ioc.Registry [ 3] Invoking constructor org.apache.tapestry5.internal.hibernate.HibernateSessionSourceImpl(Logger, List) (at HibernateSessionSourceImpl.java:36) via org.apache.tapestry5.hibernate.HibernateCoreModule.bind(ServiceBinder) (at HibernateCoreModule.java:45) (for service 'HibernateSessionSource')[ERROR] HibernateCoreModule.HibernateSessionSource Construction of service HibernateSessionSource failed: Error invoking constructor public org.apache.tapestry5.internal.hibernate.HibernateSessionSourceImpl(org.slf4j.Logger,java.util.List): No identifier specified for entity: com.fit.beans.ServiceDepartmentBeanorg.apache.tapestry5.ioc.internal.OperationException: Error invoking constructor public org.apache.tapestry5.internal.hibernate.HibernateSessionSourceImpl(org.slf4j.Logger,java.util.List): No identifier specified for entity: com.fit.beans.ServiceDepartmentBean at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.logAndRethrow(OperationTrackerImpl.java:121) at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:88) at org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:87) at org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1121) at org.apache.tapestry5.ioc.internal.util.ConstructionPlan.createObject(ConstructionPlan.java:60) at org.apache.tapestry5.ioc.internal.ConstructorServiceCreator.createObject(ConstructorServiceCreator.java:61) at org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator$1.invoke(OperationTrackingObjectCreator.java:45) at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:74) at org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:87) at org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1121) at org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator.createObject(OperationTrackingObjectCreator.java:49) at org.apache.tapestry5.ioc.internal.SingletonServiceLifecycle.createService(SingletonServiceLifecycle.java:29) at org.apache.tapestry5.ioc.internal.LifecycleWrappedServiceCreator.createObject(LifecycleWrappedServiceCreator.java:46) at org.apache.tapestry5.ioc.internal.AdvisorStackBuilder.createObject(AdvisorStackBuilder.java:63) at org.apache.tapestry5.ioc.internal.InterceptorStackBuilder.createObject(InterceptorStackBuilder.java:54) at org.apache.tapestry5.ioc.internal.RecursiveServiceCreationCheckWrapper.createObject(RecursiveServiceCreationCheckWrapper.java:60) at org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator$1.invoke(OperationTrackingObjectCreator.java:45) at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:74) at org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:87).....Caused by: java.lang.RuntimeException: Error invoking constructor public org.apache.tapestry5.internal.hibernate.HibernateSessionSourceImpl(org.slf4j.Logger,java.util.List): No identifier specified for entity: com.fit.beans.ServiceDepartmentBean at org.apache.tapestry5.ioc.internal.util.ConstructorInvoker.invoke(ConstructorInvoker.java:57) at org.apache.tapestry5.ioc.internal.util.LoggingInvokableWrapper.invoke(LoggingInvokableWrapper.java:42) at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:74) ... 72 moreCaused by: org.hibernate.AnnotationException: No identifier specified for entity: com.fit.beans.ServiceDepartmentBean at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:672) at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:546) at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:291) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1333) at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867) at org.apache.tapestry5.internal.hibernate.HibernateSessionSourceImpl.<init>(HibernateSessionSourceImpl.java:46) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at org.apache.tapestry5.ioc.internal.util.ConstructorInvoker.invoke(ConstructorInvoker.java:48) ... 74 more 解决方案 Remove constructor from@EmbeddedIdprivate ServiceDepartmentPK serviceDepartmentPK;Remove @ManyToOne annotation from ServiceDepartmentPK class and set fields types to long or int@Embeddable public class ServiceDepartmentPK implements Serializable {private static final long serialVersionUID = 1L;@Column(name="COLUMN_NAME")private long clientId;@Column(name="COLUMN_NAME")private long carServiceId;public ServiceDepartmentPK () {}// getters setters for client and carserver ids-spublic boolean equals(Object other) { if (this == other) { return true; } if (!(other instanceof ServiceDepartmentPK )) { return false; } ServiceDepartmentPK castOther = (ServiceDepartmentPK )other; return (this.scopeId == castOther.clientId) && (this.scriptId == castOther.carServiceId);}public int hashCode() { final int prime = 31; int hash = 17; hash = hash * prime + ((int) (this.clientId ^ (this.clientId>>> 32))); hash = hash * prime + ((int) (this.carServiceId ^ (this.carServiceId>>> 32))); return hash;}} 这篇关于如何创建一个复合主键休眠JPA?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-05 03:40