My bean:
@Entity
@Table(name = "Tabela_Exames_PreNatal")
@Access(value = AccessType.FIELD)
public class Bean_Pre_Natal implements Serializable
{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue( strategy = GenerationType.IDENTITY)
@Column( name = "Prontuario", updatable = true)
private String prontuario = null;
@Id
@GeneratedValue( strategy = GenerationType.IDENTITY)
@Column( name = "Data_Consulta", updatable = true)
private String data_consulta = null;
@Column( name = "Nome", updatable = true)
private String nome = null;
@Column( name = "Consulta_Do_Trimestre", updatable = true)
private String
consulta_do_trimestre = null;
@Column( name = "Semanas_Gestacao", updatable = true)
private String
semanas_gestacao = null;
... and many others fields
getter and setter of all
My HibernateUtil:
public class HibernateUtil
{
private static final SessionFactory sessionFactory = buildSessionFactory();
private static SessionFactory buildSessionFactory() {
try {
return new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
System.err.println("build SeesionFactory failed :" + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
public static void close() {
// Close all cached and active connection pools
getSessionFactory().close();
}
}
My method to save:
public void sveInsert(Bean_Pre_Natal bpreNatal)
{
try
{
Session session = HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();
session.save(bpreNatal); ==> Line error.
session.getTransaction().commit();
}catch(HibernateException he)
{
he.printStackTrace();
}
}
Log error:
02-Sep-2021 08:52:55.230 INFO [http-nio-8080-exec-77] org.hibernate.Version.logVersion HHH000412: Hibernate ORM core version 5.5.6.Final
02-Sep-2021 08:52:59.064 WARN [http-nio-8080-exec-77] org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver.resolveEntity HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-configuration. Use namespace http://www.hibernate.org/dtd/hibernate-configuration instead. Support for obsolete DTD/XSD namespaces may be removed at any time.
02-Sep-2021 08:53:03.514 INFO [http-nio-8080-exec-77] org.hibernate.annotations.common.reflection.java.JavaReflectionManager.<clinit> HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
02-Sep-2021 08:53:05.662 WARN [http-nio-8080-exec-77] org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure HHH10001002: Using Hibernate built-in connection pool (not for production use!)
02-Sep-2021 08:53:05.670 INFO [http-nio-8080-exec-77] org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.buildCreator HHH10001005: using driver [com.mysql.cj.jdbc.Driver] at URL [jdbc:mysql://localhost/DB_Medical]
02-Sep-2021 08:53:05.672 INFO [http-nio-8080-exec-77] org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.buildCreator HHH10001001: Connection properties: {password=****, user=root}
02-Sep-2021 08:53:05.673 INFO [http-nio-8080-exec-77] org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.buildCreator HHH10001003: Autocommit mode: false
02-Sep-2021 08:53:05.772 INFO [http-nio-8080-exec-77] org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PooledConnections.<init> HHH000115: Hibernate connection pool size: 10 (min=1)
02-Sep-2021 08:53:06.506 INFO [http-nio-8080-exec-77] org.hibernate.dialect.Dialect.<init> HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
02-Sep-2021 08:53:11.421 INFO [http-nio-8080-exec-77] org.hibernate.search.engine.Version.<clinit> HSEARCH000034: Hibernate Search 5.11.9.Final
02-Sep-2021 08:53:11.656 WARN [http-nio-8080-exec-77] org.hibernate.mapping.RootClass.checkCompositeIdentifier HHH000038: Composite-id class does not override equals(): com.itcsystems.beans.Bean_Pre_Natal
02-Sep-2021 08:53:11.686 WARN [http-nio-8080-exec-77] org.hibernate.mapping.RootClass.checkCompositeIdentifier HHH000039: Composite-id class does not override hashCode(): com.itcsystems.beans.Bean_Pre_Natal
02-Sep-2021 08:53:25.997 INFO [http-nio-8080-exec-77] org.hibernate.resource.transaction.backend.jdbc.internal.DdlTransactionIsolatorNonJtaImpl.getIsolatedConnection HHH10001501: Connection obtained from JdbcConnectionAccess [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess@1da306bd] for (non-JTA) DDL execution was not in auto-commit mode; the Connection 'local transaction' will be committed and the Connection will be set into auto-commit mode.
org.hibernate.PropertyAccessException: Could not set field value [POST_INSERT_INDICATOR] value by reflection : [class com.itcsystems.beans.Bean_Pre_Natal.prontuario] setter of com.itcsystems.beans.Bean_Pre_Natal.prontuario
Send Pront.: 612.123.123-00
at org.hibernate.property.access.spi.SetterFieldImpl.set(SetterFieldImpl.java:72)
at org.hibernate.mapping.Component$ValueGenerationPlan.execute(Component.java:510)
at org.hibernate.id.CompositeNestedGeneratedValueGenerator.generate(CompositeNestedGeneratedValueGenerator.java:97)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:115)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:194)
at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:38)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:179)
at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:32)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:75)
at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:107)
at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:665)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:658)
at org.hibernate.internal.SessionImpl.save(SessionImpl.java:653)
at com.itcsystems.beans.SavUpdt.sveInsert(SavUpdt.java:43)
at itc.systems.itcsystemsdemoweb.Pre_Natal_S005.doPost(Pre_Natal_S005.java:239)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:668)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1417)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.lang.IllegalArgumentException: Can not set java.lang.String field com.itcsystems.beans.Bean_Pre_Natal.prontuario to org.hibernate.id.IdentifierGeneratorHelper$2
at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
at java.base/jdk.internal.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81)
at java.base/java.lang.reflect.Field.set(Field.java:778)
at org.hibernate.property.access.spi.SetterFieldImpl.set(SetterFieldImpl.java:52)
... 38 more
I can’t any idea to solve thiss problem.
Thanks in advance.