Hibernate: select post0_.post_id as post_id1_1_, post0_.added_date as added_date2_1_, post0_.category_id as category_id6_1_, post0_.content as content3_1_, post0_.image_name as image_name4_1_, post0_.post_title as post_title5_1_, post0_.user_id as user_id7_1_ from posts post0_ fetch first ? rows only
2022-05-27 15:54:49.431 WARN 22616 --- [nio-9191-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 933, SQLState: 42000
2022-05-27 15:54:49.431 ERROR 22616 --- [nio-9191-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper : ORA-00933: SQL command not properly ended
2022-05-27 15:54:49.433 ERROR 22616 --- [nio-9191-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet] with root cause
oracle.jdbc.OracleDatabaseException: ORA-00933: SQL command not properly ended
Try to specific column names in entities:
#Column(name = "POST_ID1_1_")
private Long postId
Set correct dialect for database (application.properties). Try with:
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
I have an entity class Product that i was given READ grant on the whole entity and UPDATE grant ONLY on the price field in the database. So whenever i call productDao.update(product), even if I changed only the price field value, i`m getting
<2020-09-17 14:33:26.735 WARN 26939 --- [ (self-tuning)'] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 1031, SQLState: 42000>
<2020-09-17 14:33:26.735 ERROR 26939 --- [ (self-tuning)'] o.h.engine.jdbc.spi.SqlExceptionHelper : ORA-01031: insufficient privileges>
<2020-09-17 14:33:26.736 INFO 26939 --- [ (self-tuning)'] o.h.e.j.b.internal.AbstractBatchImpl : HHH000010: On release of batch it still contained JDBC statements>
<2020-09-17 14:33:26.737 ERROR 26939 --- [ (self-tuning)'] o.h.i.ExceptionMapperStandardImpl : HHH000346: Error during managed flush [org.hibernate.exception.SQLGrammarException: could not execute statement]>
Try using dynamic update, the generated SQL will only try to update the columns that have been modified
Maybe instead of calling the default .update() method implement your own updating method in which you just execute a HQL update statement which updates one field based on your object's value?
Maybe you could try to annotate other properties of Entity as #Column(updatable = false)
I'm stuck with this query:
#Query(value = "SELECT prfl_acct_root,string_agg(aut_right_type,',' ORDER BY aut_right_type) " +
"AS aut_right_type FROM (SELECT prf.prfl_acct_root, aut.aut_right_type " +
"FROM cov_autori aut, cov_profil prf WHERE prf.prfl_tech_idt IN " +
"(SELECT prf.prfl_tech_idt FROM cov_profil prf WHERE prfl_acct_root LIKE concat(:root,'%')) " +
"group by prf.prfl_acct_root, aut.aut_right_type) as result group by prfl_acct_root", nativeQuery = true)
Page<Root> findRootByPartialRootString(#Param("root") String root, Pageable pageable);
When this returns more than one result:
SELECT prf.prfl_tech_idt FROM cov_profil prf WHERE prfl_acct_root LIKE concat(:root,'%')
This query sends me :
06-02-2020 14:49:51.543 [http-nio-9090-exec-3] WARN SqlExceptionHelper | SQL Error: 0, SQLState: 42601
06-02-2020 14:49:51.543 [http-nio-9090-exec-3] ERROR SqlExceptionHelper | ERROR: syntax error at or near ")"
Position : 217
06-02-2020 14:49:51.558 [http-nio-9090-exec-3] DEBUG TransactionImpl | On TransactionImpl creation, JpaCompliance#isJpaTransactionComplianceEnabled == false
06-02-2020 14:49:51.564 [http-nio-9090-exec-3] DEBUG OpenEntityManagerInViewInterceptor | Closing JPA EntityManager in OpenEntityManagerInViewInterceptor
06-02-2020 14:49:51.564 [http-nio-9090-exec-3] DEBUG DispatcherServlet | Failed to complete request: org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
06-02-2020 14:49:51.564 [http-nio-9090-exec-3] DEBUG HstsHeaderWriter | Not injecting HSTS header since it did not match the requestMatcher org.springframework.security.web.header.writers.HstsHeaderWriter$SecureRequestMatcher#7ae3f246
06-02-2020 14:49:51.564 [http-nio-9090-exec-3] DEBUG SecurityContextPersistenceFilter | SecurityContextHolder now cleared, as request processing completed
06-02-2020 14:49:51.567 [http-nio-9090-exec-3] ERROR [dispatcherServlet] | Servlet.service() for servlet [dispatcherServlet] in context with path [/CashAuthGuiBackend] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet] with root causeorg.postgresql.util.PSQLException: ERROR: syntax error at or near ")"
Position : 217
I'm using spring-data-jpa-2.2.4, PostgreSQL 10.4
I have tried many options for the part:
LIKE concat(:root,'%')
such as:
LIKE ?%
LIKE ?1%
LIKE :root%
LIKE CONCATENATE(:root,'%')
The query always works when executed directly on the db tool in intellij.
Thank you for your help :)
I've got the following error:
07:27:02,736 INFO Version:37 - HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
07:27:02,745 INFO Version:41 - HHH000412: Hibernate Core {4.2.0.Final}
07:27:02,755 INFO Environment:239 - HHH000206: hibernate.properties not found
07:27:02,757 INFO Environment:342 - HHH000021: Bytecode provider name : javassist
07:27:02,799 INFO Configuration:1933 - HHH000043: Configuring from resource: ./hibernate.cfg.xml
07:27:02,799 INFO Configuration:1952 - HHH000040: Configuration resource: ./hibernate.cfg.xml
07:27:02,888 WARN DTDEntityResolver:74 - HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
07:27:02,960 INFO Configuration:2074 - HHH000041: Configured SessionFactory: null
07:27:03,677 INFO DriverManagerConnectionProviderImpl:98 - HHH000402: Using Hibernate built-in connection pool (not for production use!)
07:27:03,712 INFO DriverManagerConnectionProviderImpl:134 - HHH000115: Hibernate connection pool size: 20
07:27:03,713 INFO DriverManagerConnectionProviderImpl:137 - HHH000006: Autocommit mode: false
07:27:03,713 INFO DriverManagerConnectionProviderImpl:151 - HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost/ForBook]
07:27:03,713 INFO DriverManagerConnectionProviderImpl:156 - HHH000046: Connection properties: {user=root, password=****}
07:27:05,539 INFO Dialect:128 - HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
07:27:05,570 INFO LobCreatorBuilder:94 - HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
07:27:05,608 INFO TransactionFactoryInitiator:68 - HHH000399: Using default transaction strategy (direct JDBC transactions)
07:27:05,633 INFO ASTQueryTranslatorFactory:48 - HHH000397: Using ASTQueryTranslatorFactory
07:27:05,822 INFO Version:39 - HSEARCH000034: Hibernate Search 4.3.0.Alpha1
07:27:05,988 WARN ConfigContext:301 - HSEARCH000075: Configuration setting hibernate.search.lucene_version was not specified, using LUCENE_CURRENT.
07:27:06,703 INFO SchemaExport:343 - HHH000227: Running hbm2ddl schema export
07:27:06,704 DEBUG SchemaExport:353 - Import file not found: /import.sql
07:27:06,706 DEBUG SQL:104 - alter table BEE drop foreign key FK100622C0E7E16
07:27:07,463 DEBUG SQL:104 - drop table if exists BEE
07:27:07,829 DEBUG SQL:104 - drop table if exists HONEY
07:27:07,999 DEBUG SQL:104 - create table BEE (id integer not null auto_increment, city varchar(255), street varchar(255), myEnum varchar(255), nameOfBee varchar(255), honey_id integer not null, primary key (id))
07:27:08,533 DEBUG SQL:104 - create table HONEY (honey_id integer not null auto_increment, NAME_OF_HONEY varchar(255), taste varchar(255), primary key (honey_id))
07:27:08,955 DEBUG SQL:104 - alter table BEE add index FK100622C0E7E16 (honey_id), add constraint FK100622C0E7E16 foreign key (honey_id) references HONEY (honey_id)
07:27:10,344 INFO SchemaExport:405 - HHH000230: Schema export complete
07:27:10,667 INFO DriverManagerConnectionProviderImpl:98 - HHH000402: Using Hibernate built-in connection pool (not for production use!)
07:27:10,680 INFO DriverManagerConnectionProviderImpl:134 - HHH000115: Hibernate connection pool size: 20
07:27:10,681 INFO DriverManagerConnectionProviderImpl:137 - HHH000006: Autocommit mode: true
07:27:10,681 INFO DriverManagerConnectionProviderImpl:151 - HHH000401: using driver [org.hsqldb.jdbcDriver] at URL [jdbc:hsqldb:.]
07:27:10,681 INFO DriverManagerConnectionProviderImpl:156 - HHH000046: Connection properties: {user=sa, password=****, autocommit=true, release_mode=auto}
07:27:10,907 INFO Dialect:128 - HHH000400: Using dialect: org.hibernate.dialect.HSQLDialect
07:27:10,909 INFO LobCreatorBuilder:94 - HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
07:27:10,910 INFO TransactionFactoryInitiator:73 - HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory
07:27:10,910 INFO ASTQueryTranslatorFactory:48 - HHH000397: Using ASTQueryTranslatorFactory
07:27:10,924 WARN ConfigContext:301 - HSEARCH000075: Configuration setting hibernate.search.lucene_version was not specified, using LUCENE_CURRENT.
07:27:10,947 INFO SchemaExport:343 - HHH000227: Running hbm2ddl schema export
07:27:10,948 DEBUG SchemaExport:353 - Import file not found: /import.sql
07:27:10,948 DEBUG SQL:104 - alter table BEE drop constraint FK100622C0E7E16
07:27:10,950 ERROR SchemaExport:425 - HHH000389: Unsuccessful: alter table BEE drop constraint FK100622C0E7E16
07:27:10,950 ERROR SchemaExport:426 - Table not found: BEE in statement [alter table BEE]
07:27:10,950 DEBUG SQL:104 - drop table BEE if exists
07:27:10,951 DEBUG SQL:104 - drop table HONEY if exists
07:27:10,951 DEBUG SQL:104 - create table BEE (id integer generated by default as identity (start with 1), city varchar(255), street varchar(255), myEnum varchar(255), nameOfBee varchar(255), honey_id integer not null, primary key (id))
07:27:10,953 DEBUG SQL:104 - create table HONEY (honey_id integer generated by default as identity (start with 1), NAME_OF_HONEY varchar(255), taste varchar(255), primary key (honey_id))
07:27:10,953 DEBUG SQL:104 - alter table BEE add constraint FK100622C0E7E16 foreign key (honey_id) references HONEY
07:27:10,956 INFO SchemaExport:405 - HHH000230: Schema export complete
07:27:11,190 DEBUG SQL:104 - insert into HONEY (honey_id, NAME_OF_HONEY, taste) values (null, ?, ?)
07:27:11,191 WARN SqlExceptionHelper:143 - SQL Error: -20, SQLState: IM001
07:27:11,191 ERROR SqlExceptionHelper:144 - This function is not supported
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not prepare statement
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1387)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1310)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1316)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:881)
at ua.hibernate_project.TestWork.main(TestWork.java:88)
Caused by: org.hibernate.exception.GenericJDBCException: could not prepare statement
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:188)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareStatement(StatementPreparerImpl.java:117)
at org.hibernate.id.insert.AbstractSelectingDelegate.performInsert(AbstractSelectingDelegate.java:55)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2966)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3477)
at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:81)
at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:362)
at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:203)
at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:183)
at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:167)
at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:321)
at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:286)
at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:192)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:125)
at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:78)
at org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:208)
at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:151)
at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:78)
at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:852)
at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:826)
at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:830)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:875)
... 1 more
Caused by: java.sql.SQLException: This function is not supported
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.Util.notSupported(Unknown Source)
at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$2.doPrepare(StatementPreparerImpl.java:119)
at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:182)
... 22 more
While I try to work with entity manager (via Hibernate API all works good)
I can see entity manager tries to insert id, i.e. honey_id
DEBUG SQL:104 - insert into HONEY (honey_id, NAME_OF_HONEY, taste) values (null, ?, ?)
via Hibernate API I see follow
DEBUG SQL:104 - insert into HONEY (NAME_OF_HONEY, taste) values (?, ?)
My classes
Bee:
#Entity
#Table(name = "BEE")
public class Bee {
#ManyToOne
#JoinColumn(name = "honey_id", nullable = false)
private Honey honey;
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String nameOfBee;
#Enumerated(EnumType.STRING)
private MyEnum myEnum = MyEnum.UNNORMAL;
#Embedded
private Address address;
Honey:
#Table(name = "HONEY")
#Entity
public class Honey {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name = "honey_id")
private int id;
#Column(name = "NAME_OF_HONEY")
private String nameOfHoney;
private String taste;
#OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.ALL }, mappedBy = "honey" )
private Set<Bee> bees;
Address:
#Embeddable
public class Address {
public Address() {}
TestWork:
public class TestWork {
private static SessionFactory sessionFactory;
private static EntityManagerFactory emf;
private Session session;
static{
Configuration configuration = new Configuration();
configuration.configure("./hibernate.cfg.xml");
ServiceRegistryBuilder serviceRegistryBuilder =
new ServiceRegistryBuilder().applySettings(configuration.getProperties());
sessionFactory = configuration.buildSessionFactory(serviceRegistryBuilder.buildServiceRegistry());
emf = Persistence.createEntityManagerFactory("hibernate-search-example");
}
public Session openSessionAndGetTransaction(){
session = sessionFactory.openSession();
session.getTransaction().begin();
return session;
}
public static EntityManager getEntityManager(){
return emf.createEntityManager();
}
public void commitAndCloseSession(){
session.getTransaction().commit();
session.close();
}
public static void main(String[] args) {
TestWork testWork = new TestWork();
EntityManager em = TestWork.getEntityManager();
EntityTransaction tx = em.getTransaction();
tx.begin();
Address address = new Address("Dnipro", "K.Marksa");
Honey honeyFromForest = new Honey("FirstHoney","Very tasty");
Bee firstBee = new Bee();
firstBee.setAddress(address);
firstBee.setNameOfBee("I'm first Bee");
firstBee.setHoney(honeyFromForest);
Bee secondBee = new Bee();
secondBee.setAddress(address);
secondBee.setNameOfBee("I'm second Bee");
secondBee.setHoney(honeyFromForest);
Set<Bee> bees = new HashSet<Bee>();
bees.add(firstBee);
bees.add(secondBee);
honeyFromForest.setBees(bees);
em.persist(honeyFromForest);
em.persist(firstBee);
em.persist(secondBee);
}
Thank you for your help!
I have tried using both Hsqldb and H2 for unit testing but facing problem with sequence generators. Field declaration looks like this.
#Id #GeneratedValue(strategy=GenerationType.SEQUENCE, generator="keyword_seq")
#SequenceGenerator(name="keyword_seq",sequenceName="KEYWORD_ID_SEQ", allocationSize=1)
#Column(name="IM_KEYWORD_ID")
private Long keywordId;
When I try to test simple insert in this table in Hsqldb with following configuration, it gives error
<prop key="hibernate.connection.driver_class">org.hsqldb.jdbc.JDBCDriver</prop>
<prop key="hibernate.connection.url">jdbc:hsqldb:mem:testdb;sql.syntax_ora=true</prop>
Error :
Caused by: java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: KEYWORD_ID_SEQ.NEXTVAL
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
With H2:
<prop key="hibernate.connection.driver_class">org.h2.Driver</prop>
<prop key="hibernate.connection.url">jdbc:h2:~/test</prop>
Error is :
Hibernate: select KEYWORD_ID_SEQ.nextval from dual
3085 [main] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 42001, SQLState: 42001
3088 [main] ERROR org.hibernate.util.JDBCExceptionReporter - Syntax error in SQL statement "SELECT KEYWORD_ID_SEQ.NEXTVAL FROM[*] DUAL "; expected "identifier"; SQL statement:
Any idea, how to solve this?
I think the dialect is set wrongly. Can you check your hibernate configuration.