I have a groovy entity ClientInvoiceAttachmentExt which extends java entity ClientInvoiceAttachment. The ClientInvoiceAttachment has #Id annotation but still am seeing the "No identifier specified for entity" error
Here is my stack trace
[Mar 03 17:11:54] ERROR | org.springframework.web.context.ContextLoader | Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'collaborationAPI': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: public com.dc.apps.collaborationportal.security.service.CollaborationSecurityService com.dc.apps.collaborationportal.core.api.CollaborationAPI.security; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'collaborationSecurityService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected com.dc.apps.collaborationportal.feature.service.FeatureService com.dc.apps.collaborationportal.security.service.CollaborationSecurityService.featureService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'featureService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.dc.core.api.Services com.dc.apps.collaborationportal.feature.service.FeatureService.api; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'services': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: public com.dc.core.api.SearchAPI com.dc.core.api.Services.search; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'searchAPI': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private transient org.hibernate.SessionFactory com.dc.core.entity.service.impl.QueryService.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is com.dc.core.common.exception.BaseApplicationException: org.hibernate.AnnotationException: No identifier specified for entity: com.dc.apps.collaborationportal.ebilling.model.impl.ClientInvoiceAttachmentExt
Caused by: org.hibernate.AnnotationException: No identifier specified for entity: com.dc.apps.collaborationportal.ebilling.model.impl.ClientInvoiceAttachmentExt
at org.hibernate.cfg.InheritanceState.determineDefaultAccessType(InheritanceState.java:268)
at org.hibernate.cfg.InheritanceState.getElementsToProcess(InheritanceState.java:223)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:686)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:4035)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3989)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1398)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1375)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:720)
at com.dc.core.entity.support.CustomFieldsSessionFactoryBean.buildSessionFactory(CustomFieldsSessionFactoryBean.java:252)
... 94 more
My pom dependancies
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.6.10.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search</artifactId>
<!-- this is the latest version that works with lucene-core 3.0.3
(which we are stuck with until jackrabbit supports later versions) -->
<version>3.3.0.Final</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>ejb3-persistence</artifactId>
</exclusion>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
Here is my Java class
package com.dc.apps.collaborationportal.ebilling.model.impl;
import javax.persistence.AssociationOverride;
import javax.persistence.Embedded;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Transient;
import org.hibernate.annotations.Entity;
import com.dc.core.common.annotations.AttributeMetadataDefaults;
import com.dc.core.common.annotations.EventDefaults;
import com.dc.core.common.annotations.EventHandlerDefaults;
import com.dc.core.entity.model.IPersistentEntityInstance;
import com.dc.core.entity.model.impl.File;
import com.dc.core.events.enums.EventTypeEnum;
import com.dc.core.security.annotation.AttributeReadPermission;
import com.dc.core.security.annotation.AttributeWritePermission;
import com.dc.core.security.annotation.ContainerReference;
#Entity
#EventDefaults({
#EventHandlerDefaults(eventType = EventTypeEnum.OnBeforeCreate, beanName = "checksumInvoiceAttachmentCommand"),
#EventHandlerDefaults(eventType = EventTypeEnum.OnBeforeCreate, beanName = "encryptInvoiceAttachmentCommand") })
public class ClientInvoiceAttachment implements IPersistentEntityInstance {
private static final long serialVersionUID = 1L;
private Long id;
private File attachment;
private String checksum;
private String invoiceNumber;
#Embedded
#AssociationOverride(name = "fileData", joinColumns = #JoinColumn(name = "attachment_file_data_id"))
public File getAttachment() {
return attachment;
}
public String getChecksum() {
return checksum;
}
#Transient
#AttributeMetadataDefaults(defaultDisplay = true)
public String getFileName() {
if (attachment == null) return "";
return attachment.getName();
}
#Id
#GeneratedValue
public Long getId() {
return id;
}
public String getInvoiceNumber() {
return invoiceNumber;
}
public void setAttachment(File attachment) {
this.attachment = attachment;
}
public void setChecksum(String checksum) {
this.checksum = checksum;
}
public void setId(Long id) {
this.id = id;
}
public void setInvoiceNumber(String invoiceNumber) {
this.invoiceNumber = invoiceNumber;
}
}
Here is my groovy class
package com.dc.apps.collaborationportal.ebilling.model.impl
import com.dc.core.api.Services;
import java.util.List
import javax.persistence.Column
import javax.persistence.OneToMany
import javax.persistence.ManyToMany
import javax.persistence.ManyToOne
import javax.persistence.Cacheable
import javax.persistence.Transient
import javax.persistence.JoinColumn
import javax.persistence.Embedded
import javax.persistence.Id
import javax.persistence.GeneratedValue
import javax.persistence.OneToOne
import javax.persistence.AssociationOverride
import javax.persistence.Lob
import javax.persistence.FetchType
import javax.persistence.Entity
import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Indexed
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.Store;
import org.hibernate.annotations.NamedQueries
import org.hibernate.annotations.NamedQuery
import org.hibernate.envers.Audited
import org.hibernate.envers.NotAudited
import org.hibernate.annotations.Cascade
import org.hibernate.annotations.Type
//import org.hibernate.annotations.Index
import org.hibernate.annotations.LazyCollection
import org.hibernate.annotations.LazyCollectionOption
import org.hibernate.annotations.Formula
import org.hibernate.annotations.Fetch
import org.hibernate.annotations.FetchMode
import org.hibernate.annotations.BatchSize
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.ApplicationContext
import org.springframework.context.ApplicationContextAware
import org.springframework.beans.BeansException
import com.dc.core.entity.enums.VersionStatusEnum
import com.dc.core.behavior.command.model.ICommandResult
import com.dc.core.behavior.command.model.impl.CommandResult
import com.dc.core.behavior.command.model.IEntityInstanceCommand
import com.dc.core.entity.model.IPersistentEntityInstance
import com.dc.core.behavior.trackchanges.model.IEntityChangeset
import com.dc.core.security.model.IContainer
import com.dc.core.security.annotation.ContainerReference
import com.dc.core.security.annotation.Encrypted
import com.dc.core.collaboration.enums.CollaborationRequestStatus
import com.dc.core.collaboration.model.ICollaborationParcel
import com.dc.core.collaboration.model.ICollaborationFeatureDetail
import org.hibernate.annotations.Cache
import org.hibernate.annotations.CacheConcurrencyStrategy
#javax.persistence.Entity
class ClientInvoiceAttachmentExt extends com.dc.apps.collaborationportal.ebilling.model.impl.ClientInvoiceAttachment implements IAmGroovy, Serializable {
#Autowired
protected transient Services services;
private static final long serialVersionUID = 711967972L;
public java.lang.String getCreatedBy() {
return this.createdBy;
}
public void setCreatedBy(java.lang.String createdBy) {
this.createdBy = createdBy;
}
protected createdBy;
public java.lang.String getUpdatedBy() {
return this.updatedBy;
}
public void setUpdatedBy(java.lang.String updatedBy) {
this.updatedBy = updatedBy;
}
protected updatedBy;
public java.sql.Timestamp getCreatedAt() {
return this.createdAt;
}
public void setCreatedAt(java.sql.Timestamp createdAt) {
this.createdAt = createdAt;
}
protected createdAt;
public java.sql.Timestamp getUpdatedAt() {
return this.updatedAt;
}
public void setUpdatedAt(java.sql.Timestamp updatedAt) {
this.updatedAt = updatedAt;
}
protected updatedAt;
protected transient ApplicationContext applicationContext;
}
Your problem scenario is of Inheritance Mapping. The Id field is there in your super class but what about your child class, how they will be related to their parent.
There are different strategy to map an Inheritance hierarchy.
Using Discriminator value (Single Table)
Table per concrete class
Table per Child class (if parent is an abstract)
I think you are missing annotations related to above.
In Discriminator based approach.. You need to annotate your ParentClass as follows:
#Inheritance(strategy=InheritanceType.SINGLE_TABLE)
#DiscriminatorColumn(name="type",discriminatorType=DiscriminatorType.STRING)
#DiscriminatorValue(value="ParentClass")
And in you child class:
#DiscriminatorValue("childClasss")
Please refer some tutorial on Inheritance Mapping like this one or you can google it.
There is a new annotation #MappedSuperclass that you add to the base class and it only affects the OOP without the need to change the DB. That is what I was looking for. You can read more about it in this post
I got the same error while working with JPA & I have added the #Id annotation,
While working with JPA, kindly make sure that this #Id annotation should be from package javax.persistence.Id & not from org.springframework.data.annotation.Id.
Hope it can save your precious time.
I saw the similar error. In case you have a Class which has a one to one relation with other class , that other class should have a Primary key as an identifier. (My app was using spring boot,jpa,h2,lombok)
Ex:
#Entity
#Getter
#Setter
Class A{
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
#OneToOne(cascade = CascadeType.ALL)
#JoinColumn(name="b")
public B b;
}
Now the similar error might be raised if you missed writing the primary key or an identifier for the class B which is shown below
#Entity
#Getter
#Setter
Class b{
/* Same error may be raised when he below code is missing*/
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long b_id;
#OneToOne(mappedBy = "bid")
public A a;
}
Related
I am having a hard time staring up my server with spring. I looked up similar errors to mine and it seemed it had to do with the way I used RequestMapping. Despite having tried various methods to define my routes, I still can't figure out what seems to be the problem. Any ideas?
This is my error message:
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'requestMappingHandlerAdapter' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Unsatisfied dependency expressed through method 'requestMappingHandlerAdapter' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcConversionService' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.format.support.FormattingConversionService]: Factory method 'mvcConversionService' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'qualificationRepository' defined in com.salay.christophersalayportfolio.repositories.QualificationRepository defined in #EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Cannot resolve reference to bean 'jpaMappingContext' while setting bean property 'mappingContext'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.salay.christophersalayportfolio.models.ProgrammingLanguage.dissertation in com.salay.christophersalayportfolio.models.Dissertation.programmingLanguages
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'requestMappingHandlerAdapter' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Unsatisfied dependency expressed through method 'requestMappingHandlerAdapter' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcConversionService' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.format.support.FormattingConversionService]: Factory method 'mvcConversionService' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'qualificationRepository' defined in com.salay.christophersalayportfolio.repositories.QualificationRepository defined in #EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Cannot resolve reference to bean 'jpaMappingContext' while setting bean property 'mappingContext'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.salay.christophersalayportfolio.models.ProgrammingLanguage.dissertation in com.salay.christophersalayportfolio.models.Dissertation.programmingLanguages
My TaskController
import com.salay.christophersalayportfolio.models.Task;
import com.salay.christophersalayportfolio.repositories.TaskRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Optional;
#RestController
#RequestMapping(path = "/api/v1/tasks")
public class TaskController {
#Autowired
private TaskRepository taskRepository;
#RequestMapping(value = "/add", method = RequestMethod.POST)
public #ResponseBody String add(#RequestBody Task task) {
taskRepository.save(task);
return "Successfully saved the task to the database.";
}
#RequestMapping(value = "/{id/", method = RequestMethod.GET)
public Task getById(#PathVariable int id){
Optional<Task> task = taskRepository.findById(id);
if(!task.isPresent()){
throw new NullPointerException();
}
else {
return task.get();
}
}
#RequestMapping(value = "/all/", method = RequestMethod.GET)
public List<Task> getAll() {
return taskRepository.findAll();
}
}
My ProgrammingLanguagesController:
package com.salay.christophersalayportfolio.controllers;
import com.salay.christophersalayportfolio.models.ProgrammingLanguage;
import com.salay.christophersalayportfolio.repositories.ProgrammingLanguageRepositories;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Optional;
#RestController
#RequestMapping(path = "/api/v1/programmingLanguages")
public class ProgrammingLanguageController {
#Autowired
private ProgrammingLanguageRepositories plRepository;
#RequestMapping( value= "/add", method = RequestMethod.POST)
public #ResponseBody String add(#RequestBody ProgrammingLanguage pl){
plRepository.save(pl);
return "This programming language has been successfully saved";
}
#RequestMapping( value = "/{id}/", method = RequestMethod.GET)
public ProgrammingLanguage getById(#PathVariable int id){
Optional<ProgrammingLanguage> pl = plRepository.findById(id);
if( !pl.isPresent()){
throw new NullPointerException();
}
else {
return pl.get();
}
}
#RequestMapping( value = "/all", method = RequestMethod.GET)
public List<ProgrammingLanguage> getAll(){
return plRepository.findAll();
}
}
Below are my entities:
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
#Entity
public class ProgrammingLanguage {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private int id;
public String name;
public String image;
}
import javax.persistence.*;
import java.util.Set;
#Entity
public class Dissertation {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private int id;
private int qualificationId;
public String title;
#OneToMany(mappedBy="dissertation")
public Set<ProgrammingLanguage> programmingLanguages;
public Set<Tool> tools;
}
package com.salay.christophersalayportfolio.models;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
#Entity
public class Task {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private int id;
private int experienceId;
private int projectId;
public String description;
}
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
#Entity
public class Task {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private int id;
private int experienceId;
private int projectId;
public String description;
}
import javax.persistence.*;
import java.util.Set;
#Entity
public class Project {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private int id;
public String name;
public String description;
public String client;
#OneToMany(mappedBy = "project")
public Set<ProgrammingLanguage> programmingLanguages;
#OneToMany(mappedBy = "project")
public Set<Tool> tools;
#OneToMany(mappedBy = "project")
public Set<String> images;
#OneToMany(mappedBy = "project")
public Set<Task> tasks;
}
My pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.salay</groupId>
<artifactId>christopher-salay-portfolio</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>christopher-salay-portfolio</name>
<description>Back-end application for my portfolio</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc -->
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>8.3.1.jre14-preview</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
The problem is not in your request mapping, your app does not start because of an issue in your entity mapping, please double check your mappings as stated in your error: mappedBy reference an unknown target entity
org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.salay.christophersalayportfolio.models.ProgrammingLanguage.dissertation in com.salay.christophersalayportfolio.models.Dissertation.programmingLanguages
It seems your class com.salay.christophersalayportfolio.models.ProgrammingLanguage does not have a property named dissertation
Otherwise, share your model to take a look!
I'm getting this error in a SpringBoot project. The query I'm running is working up until the point when I try to save a Consumer entity to the Spring JPA database.
Have you any ideas on how to fix this?? I think it might be to do with the way the classes are set up.
ERROR MESSAGE:
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'entityManagerFactory' defined in class path
resource
[org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]:
Invocation of init method failed; nested exception is
javax.persistence.PersistenceException: [PersistenceUnit: default]
Unable to build Hibernate SessionFactory; nested exception is
org.hibernate.MappingException: Could not determine type for:
com.fintechbankapi.Consumer.KYCNote, at table: consumer_kyc_notes, for
columns: [org.hibernate.mapping.Column(kyc_notes)]
CLASSES BELOW - I have included no argument constructor, constructor with arguments and getters and setters in each class.
import java.util.ArrayList;
import java.util.List;
import javax.persistence.ElementCollection;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.Id;
//Object to store a Consumer's details.
#Entity
public class Consumer {
//variables
#Id
private String user_id;
#ElementCollection
private List<String> digital_footprint = new ArrayList<String>();
#ElementCollection
private List<String> contact_id = new ArrayList<String>();
#ElementCollection
private List<Contact> contacts = new ArrayList<Contact>();
#Embedded
private KYC kyc;
#ElementCollection
private List<KYCNote> kyc_notes = new ArrayList<KYCNote>();
private String address_id;
#ElementCollection
private List<Address> addresses = new ArrayList<Address>();
}
public class KYCNote {
//variables
private String code;
private String detail;
}
#Embeddable
public class KYC {
//variables
#Column(name="status")
private String status;
//An array containing information required to be verified. Will only be
//present if kyc.status = "review".
#Column(name="idv_required")
#ElementCollection
List<String> idv_required = new ArrayList<String>();
}
public class Contact {
//variables
private String id;
}
public class Address {
//variables
private String id;
}
Any help appreciated. Thanks.
Have you tried adding the following to your application.properties file?
"spring.jpa.hibernate.use-new-id-generator-mappings= false" ...
I'm in the process of learning java spring. Now I am trying to retrieve data from the database. I rely on this tutorial https://dzone.com/articles/spring-boot-and-spring-jdbc-with-h2
When I try to get data from the database via ID I get this error:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:542)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalStateException: Failed to execute CommandLineRunner
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:782)
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:763)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:318)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1213)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1202)
at com.exam.kino.KinoApplication.main(KinoApplication.java:25)
... 6 more
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.exam.kino.database.Seans]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.exam.kino.database.Seans.<init>()
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:129)
at org.springframework.jdbc.core.BeanPropertyRowMapper.mapRow(BeanPropertyRowMapper.java:285)
at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:94)
at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:61)
at org.springframework.jdbc.core.JdbcTemplate$1.doInPreparedStatement(JdbcTemplate.java:678)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:616)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:668)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:699)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:711)
at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:782)
at com.exam.kino.repository.SeansRepository.findById(SeansRepository.java:26)
at com.exam.kino.repository.SeansRepository$$FastClassBySpringCGLIB$$a208ec27.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
at com.exam.kino.repository.SeansRepository$$EnhancerBySpringCGLIB$$b326407c.findById(<generated>)
at com.exam.kino.KinoApplication.run(KinoApplication.java:31)
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:779)
... 11 more
Caused by: java.lang.NoSuchMethodException: com.exam.kino.database.Seans.<init>()
at java.lang.Class.getConstructor0(Class.java:3082)
at java.lang.Class.getDeclaredConstructor(Class.java:2178)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:122)
... 31 more
This is my database (schema.sql and import.sql):
create table seans
(
id integer not null AUTO_INCREMENT,
title varchar(255) not null,
datetime TIMESTAMP not null,
primary key(id)
);
INSERT INTO seans (id, title, DATETIME) VALUES (1,'Captain America',parsedatetime('30-06-2016 08:00', 'dd-MM-yyyy hh:mm'));
INSERT INTO seans (id, title, DATETIME) VALUES (2,'Antman',parsedatetime('30-06-2016 10:00', 'dd-MM-yyyy hh:mm'));
INSERT INTO seans (id, title, DATETIME) VALUES (3,'Ironman',parsedatetime('30-06-2016 12:00', 'dd-MM-yyyy hh:mm'));
Seans class (I used Lombok and annotation #Data here):
package com.exam.kino.database;
import java.sql.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import lombok.Data;
#Data
#Table(name="seans")
#Entity
public class Seans {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
#Column(name = "id")
private int id;
#Column(name = "title")
private String title;
#Column(name = "datetime")
private Date datetime;
public Seans(int id, String title, Date datetime) {
super();
this.id = id;
this.title = title;
this.datetime = datetime;
}
}
My repository class:
package com.exam.kino.repository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import com.exam.kino.database.Seans;
import antlr.collections.List;
#Repository
public class SeansRepository
{
#Autowired
JdbcTemplate jdbcTemplate;
public Seans findById(long id) {
return jdbcTemplate.queryForObject("select * from seans where id=? ", new Object[] {
id
},new BeanPropertyRowMapper<Seans>(Seans.class));
}
}
And last my main class with method call:
package com.exam.kino;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import com.exam.kino.repository.SeansRepository;
#SpringBootApplication
public class KinoApplication implements CommandLineRunner {
private Logger logger = LoggerFactory.getLogger(this.getClass());
#Autowired
SeansRepository repository;
public static void main(String[] args) {
SpringApplication.run(KinoApplication.class, args);
}
#Override
public void run(String... args) throws Exception {
logger.info("Seans id 1 - > {}", repository.findById(1));
}
}
Somebody had this type of error and know how repair this?
You can have the no-arg-constructor created by Lombok by adding one more annotation:
#Data
#NoArgsConstructor
#Table(name="seans")
#Entity
public class Seans {
// ...
}
}
and do not declare your own constructor; #NoArgsConstructor and #RequiredArgsConstructor (which is implicit by using #Data) will only work if you do not have custom constructors.
From your error logs,
Caused by: java.lang.NoSuchMethodException: com.exam.kino.database.Seans.<init>()
It is looking for a default constructor. Try defining a default constructor in Seans class.
Recommendation for getting data with spring boot
You can extend CRUDRepository or JPARepository to your Repository class to fetch data. Repository will construct the table and query itself.
You can follow this guide
https://spring.io/guides/gs/accessing-data-jpa/
As mentioned above:
More attentively read stack trace messages - there you can find information about your error.
You need to read JPA specification (https://download.oracle.com/otndocs/jcp/persistence-2_2-mrel-eval-spec/index.html), here you will find much information.
It is your case:
"The entity class must have a no-arg constructor. The entity class may have other constructors as well. The no-arg constructor must be public or protected"
I am using Spring data JPA for persistence and have configured Spring via annotation.
1)Spring configuration class
package com.karthik.config;
import javax.sql.DataSource;
import org.apache.commons.dbcp.BasicDataSource;
import org.apache.log4j.Logger;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.JpaVendorAdapter;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.Database;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
#Configuration
#EnableWebMvc
#ComponentScan(basePackages = "com.karthik")
#EnableJpaRepositories("com.karthik.repository")
public class AppConfig {
private static final Logger logger = Logger.getLogger(AppConfig.class);
#Bean
public DataSource dataSource() {
BasicDataSource dataSource = new org.apache.commons.dbcp.BasicDataSource();
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setUrl("**********");
dataSource.setUsername("******");
dataSource.setPassword("*****");
logger.info("DATA SOURCE CONFIGURED");
return dataSource;
}
#Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource, JpaVendorAdapter jpaVendorAdapter) {
LocalContainerEntityManagerFactoryBean lef = new LocalContainerEntityManagerFactoryBean();
lef.setDataSource(dataSource);
lef.setJpaVendorAdapter(jpaVendorAdapter);
lef.setPackagesToScan("com.karthik");
return lef;
}
#Bean
public JpaVendorAdapter jpaVendorAdapter() {
HibernateJpaVendorAdapter hibernateJpaVendorAdapter = new HibernateJpaVendorAdapter();
hibernateJpaVendorAdapter.setShowSql(true);
hibernateJpaVendorAdapter.setGenerateDdl(true);
hibernateJpaVendorAdapter.setDatabase(Database.MYSQL);
return hibernateJpaVendorAdapter;
}
#Bean
public PlatformTransactionManager transactionManager() {
return new JpaTransactionManager();
}
}
2) Entity classes
There is one to many mapping between hotel and rooms
HotelEntity
package com.karthik.entity;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
#Entity
#Table(name="hotels")
public class HotelEntity {
#Id
#GeneratedValue
#Column(name="mh_id")
private Long id;
#Column(name="mh_name", length=100, nullable=false)
private String name;
#Column(name="mh_description", length=500, nullable=false)
private String description;
#Temporal(TemporalType.TIMESTAMP)
#Column(name="mh__created_on", nullable=false)
private Date createdOn;
#OneToMany(fetch = FetchType.LAZY, mappedBy = "hotelId")
private Set<RoomEntity> rooms = new HashSet<>(0);
public HotelEntity(){
}
//field getters and setters
}
RoomEntity
package com.karthik.entity;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
#Entity
#Table(name="rooms")
public class RoomEntity {
#Id
#GeneratedValue
#Column(name="mr_id")
private Long id;
#Column(name="mr_code", length=50)
private String code;
#Column(name="mr_roomtype_name", nullable=false, length=50)
private String roomType;
#ManyToOne(fetch = FetchType.LAZY)
#JoinColumn(name = "mr__hotelId", nullable = false)
private Integer hotelId;
public RoomEntity() {
}
//field getters and setters
}
pom.xml
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.4.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.8.Final</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.27</version>
</dependency>
The above code works fine when there is no mapping between hotel and room entities.
But when mapping is added, there is error at the time of deployment itself. Below is the error I see in the console :
Nov 25, 2016 8:09:08 AM org.apache.catalina.core.StandardContext startInternal
SEVERE: One or more listeners failed to start. Full details will be found in the appropriate container log file
Nov 25, 2016 8:09:08 AM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/services] startup failed due to previous errors
I do not see the any exception/root cause of error in the console which is making it difficult to debug. I just see one WARN message on the console :
WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
Nov 25, 2016 7:53:34 AM org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation
1) What is wrong in the mapping that causing the above error?
2) How to capture the error/exception stack trace on console?
3) What does the deprecation message mean? How to change/update the persistence provider?
4) Do I need to use different data source(Currently using DBCP data source) to support mappings?
Please answer all the above questions.
Your relationship should be based on Entity
In RoomEntity
#ManyToOne(fetch = FetchType.LAZY)
#JoinColumn(name = "mr__hotelId", nullable = false)
private Hotel hotel;
In Hotel
#OneToMany(fetch = FetchType.LAZY, mappedBy = "hotel")
private Set<RoomEntity> rooms = new HashSet<>(0);
Generally the relations are more effective between tables in the database. Here the entity classes are treated as relational tables (concept of JPA).
#Entity
#Table(name="hotels")
public class HotelEntity {
.
.
.
#OneToMany(fetch = FetchType.LAZY, mappedBy = "hotel")
private Set<RoomEntity> rooms = new HashSet<>(0);
.
.
.
}
#Entity
#Table(name="rooms")
public class RoomEntity {
.
.
.
#ManyToOne(fetch = FetchType.LAZY)
#JoinColumn(name = "hotel_id", nullable = false)
private Hotel hotel;
.
.
.
}
Since many to one are (almost) always the owner side of a bidirectional relationship in the JPA spec, the one to many association is annotated by #OneToMany(mappedBy=...)
org.hibernate.ejb.HibernatePersistence class is deprecated and add following lines in entityManagerFactory method. it solve the persistence provider issue.
LocalContainerEntityManagerFactoryBean lef = new LocalContainerEntityManagerFactoryBean();
lef.setPersistenceProvider(new HibernatePersistenceProvider());
I'm having a bit of a rough time with JPQL (using Hibernate).
I have 2 Entities:
package org.oscarehr.common.model;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.OneToMany;
import javax.persistence.PrePersist;
import javax.persistence.JoinColumn;
import javax.persistence.CascadeType;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
#Entity
#Table(name="spireAccessionNumberMap")
public class SpireAccessionNumberMap extends AbstractModel<Integer> {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
#Column(name="uaccn")
private Integer uaccn;
#OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
#JoinColumn(name="uaccn_id", referencedColumnName="id")
private List<SpireCommonAccessionNumber> commonAccessionNumbers = new ArrayList<SpireCommonAccessionNumber>();
public SpireAccessionNumberMap() {
}
public SpireAccessionNumberMap(Integer uniqueAccn) {
this.uaccn = uniqueAccn;
}
//#Override
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getUniqueAccessionNumber() {
return uaccn;
}
public void setUniqueAccessionNumber(Integer uaccn) {
this.uaccn = uaccn;
}
public List<SpireCommonAccessionNumber> getCommonAccessionNumbers() {
return commonAccessionNumbers;
}
#PrePersist
public void prePersist() {
Iterator<SpireCommonAccessionNumber> i = this.commonAccessionNumbers.iterator();
SpireCommonAccessionNumber commonAccessionNumber;
while(i.hasNext()) {
commonAccessionNumber = i.next();
commonAccessionNumber.setUniqueAccessionId(this.uaccn);
}
}
}
and
package org.oscarehr.common.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
#Entity
#Table(name="spireCommonAccessionNumber")
public class SpireCommonAccessionNumber extends AbstractModel<Integer> {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
#Column(name="caccn")
private String caccn;
#ManyToOne
#JoinColumn(name="uaccn_id", referencedColumnName="id")
private Integer uaccn_id;
//#Override
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getCommonAccessionNumber() {
return caccn;
}
public void setCommonAccessionNumber(String caccn) {
this.caccn = caccn;
}
public Integer getUniqueAccessionId() {
return uaccn_id;
}
public void setUniqueAccessionId(Integer uaccn_id) {
this.uaccn_id = uaccn_id;
}
}
Basically, I have the 'map' object, which has a unique number associated with it. The map object has a 'link' to 1 or more 'commonNumber' objects, which store a 'common' number.
The idea is to be able to map lots of common numbers to a unique number using the JPQL and 'Dao's.
However, when I deploy my java WAR file, I get this error:
2013-01-04 13:42:12,344 INFO [Version:14] Hibernate Commons Annotations 3.1.0.GA
2013-01-04 13:42:12,347 INFO [Version:16] Hibernate EntityManager 3.4.0.GA
2013-01-04 13:42:17,753 ERROR [ContextLoader:215] Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [spring_jpa.xml]: Invocati
on of init method failed; nested exception is org.hibernate.AnnotationException: #OneToOne or #ManyToOne on org.oscarehr.common.model.SpireCommonAccessionNumber.uaccn_
id references an unknown entity: java.lang.Integer
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:567)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at org.oscarehr.common.web.OscarSpringContextLoader.createWebApplicationContext(OscarSpringContextLoader.java:97)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:943)
at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:778)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:504)
at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1385)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:306)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1389)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1653)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1662)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1642)
at java.lang.Thread.run(Thread.java:679)
Caused by: org.hibernate.AnnotationException: #OneToOne or #ManyToOne on org.oscarehr.common.model.SpireCommonAccessionNumber.uaccn_id references an unknown entity: java.lang.Integer
at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:81)
at org.hibernate.cfg.AnnotationConfiguration.processEndOfQueue(AnnotationConfiguration.java:456)
at org.hibernate.cfg.AnnotationConfiguration.processFkSecondPassInOrder(AnnotationConfiguration.java:438)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:309)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1148)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1226)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:173)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:854)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:425)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:131)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:257)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
... 28 more
I'm at a bit of a loss here...I've tried fiddling around with different ways to map the 'common' object to the 'map' object, but I keep getting errors.
Would anyone be able to shed some light on this for me?
The mapping for the #ManyToOne seems like it should be.
#ManyToOne()
#JoinColumn(name="uaccn_id")
private SpireAccessionNumberMap spireAccessionNumberMap;
public SpireAccessionNumberMap getSpireAccessionNumberMap() {
return spireAccessionNumberMap;
}
public void setSpireAccessionNumberMap(
SpireAccessionNumberMap spireAccessionNumberMap) {
this.spireAccessionNumberMap = spireAccessionNumberMap;
}
The OneToMany side needs the following mapping.
#OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER,mappedBy="spireAccessionNumberMap")
private List<SpireCommonAccessionNumber> commonAccessionNumbers = new ArrayList<SpireCommonAccessionNumber>();