0
I need to solve a question of using inheritance and sequences with Hibernate and Oracle.
I’m using Maven with:
hibernate-core 5.1.5.Final
hibernate-entitymanager 5.1.5.Final
hibernate-validator 5.1.3.Final
eclipselink 2.6.5
ojdbc6 11.2.0.4
javax.persistence 2.1.1
hibernate-jpa-2.1-api 1.0.0.Final
I have my EntidadeDominio
, in which all classes extend.
Entidadedominio
@MappedSuperclass
public class EntidadeDominio implements IEntidade, Serializable {
private static final long serialVersionUID = -5377726703339445533L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE ,generator = "SQ")
private Integer id;
//Getter e Setters omitidos
}
Class example: Email
@Entity
@Table(name = "EMAIL")
@AttributeOverride(name = "id", column = @Column(name = "COD_EMAIL"))
@SequenceGenerator(name="SQ", sequenceName = "SEQ_EMAIL", allocationSize = 1)
public class EmailEnvio extends EntidadeDominio{
...
}
Each entity uses a different Quence, because the Bank is oracle and it will be responsible for generating this Quence (business rule).
I did several searches for the internet where all had the same code I put, but I only get the error that
org.hibernate.Annotationexception: Unknown Id.Enerator: SQ
as follows the Stacktracer below.
Is there any other way to use these annotations?
@GeneratedValue(strategy = GenerationType.SEQUENCE ,generator = "SQ")
@SequenceGenerator(name="SQ", sequenceName = "SEQ_EMAIL", allocationSize = 1)
Or am I using the wrong libraries? I tried several code changes but could not solve, I do not have much experience with Hibernate + oracle.
From now on I appreciate the help of anyone who can help!
Stacktracer:
29-May-2018 14:46:52.888 INFO [http-nio-8084-exec-21] org.apache.catalina.core.ApplicationContext.log Marking servlet Servlet as unavailable
29-May-2018 14:46:52.888 SEVERE [http-nio-8084-exec-21] org.apache.catalina.core.StandardWrapperValve.invoke Allocate exception for servlet Servlet
org.hibernate.AnnotationException: Unknown Id.generator: SQ
at org.hibernate.cfg.BinderHelper.makeIdGenerator(BinderHelper.java:664)
at org.hibernate.cfg.AnnotationBinder.processId(AnnotationBinder.java:2360)
at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:2265)
at org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:913)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:740)
at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.processEntityHierarchies(AnnotationMetadataSourceProcessorImpl.java:245)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.processEntityHierarchies(MetadataBuildingProcess.java:222)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:265)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:848)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:875)
at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:58)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
at com.projart.core.dao.DaoFactory.entityManagerFactorInstance(DaoFactory.java:51)
at com.projart.core.dao.AbstractJdbcDAO.<init>(AbstractJdbcDAO.java:61)
at com.projart.core.dao.imp.UsuarioDAO.<init>(UsuarioDAO.java:31)
at com.projart.core.imp.Fachada.<init>(Fachada.java:120)
at com.projart.view.command.imp.AbstractCommand.<init>(AbstractCommand.java:27)
at com.projart.view.command.imp.SalvarCommand.<init>(SalvarCommand.java:26)
at com.projart.view.Servlet.<init>(Servlet.java:67)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:121)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1095)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:817)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
There is the
SequenceGenerator
in the Oracle database with the name "SQ"?– Paulo H. Hartmann
Yes there is. CREATE SEQUENCE SQ MINVALUE 1 MAXVALUE 9999999 INCREMENT BY 1 START WITH 1 NOCACHE;
– Dani
You didn’t reverse the references in
name
andsequenceName
? Link– StatelessDev
I just reviewed and this right the orders of name and sequence T.T
– Dani
I’ve used it with code like this:
@MappedSuperclass
public class EntidadeDominio implements IEntidade, Serializable {

 @Id
 @GeneratedValue(generator="increment")
 @GenericGenerator(name="increment", strategy = "increment") 
 @Column(nullable = false, insertable = true, updatable = true)
 public Integer id;
But I need to use Quence– Dani