Prop Key Hibernate.id.new_generator_mappings False Prop
- Dear Brett, i am facing one issue while using hikariCP for oracle DB connection. I am using atomikos for transaction management. Problem if i am keeping autocommit as false transaction is not getti.
- Nov 08, 2017 Dear Brett, i am facing one issue while using hikariCP for oracle DB connection. I am using atomikos for transaction management. Problem if i am keeping autocommit as false transaction is not getting committed although Jta is calling com.
- Codesenior.COM is a web site which contains articles and codes related to Java, Android, PHP, C#/ASP.NET, C/C etc.
- @ContextHierarchy({
- @ContextConfiguration(value = 'file:src/main/webapp/WEB-INF/spring/applicationContext-db.xml'),
- @ContextConfiguration(value = 'file:src/main/webapp/WEB-INF/spring/applicationContext.xml')
- public class FileServiceImplTest {
- @Autowired
- public void testSaveFolder() {
- rootFolder.setName('ROOT');
- rootFolder.setIdPath('/');
- List<AbstractFileDTO> rootFiles = fileService.getRootFiles();
- assertEquals(1, rootFiles.size());
- AbstractFileDTO abstractFileDTO = rootFiles.get(0);
- assertEquals(rootFolder, abstractFileDTO);
- }
- }
- org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread
- at org.springframework.orm.hibernate5.SpringSessionContext.currentSession(SpringSessionContext.java:132)
- at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:697)
- at org.sbezgin.p2016.db.dao.impl.FileDAOImpl.getSession(FileDAOImpl.java:69)
- at org.sbezgin.p2016.db.dao.impl.FileDAOImpl.saveOrUpdateFile(FileDAOImpl.java:33)
- at org.sbezgin.p2016.services.file.impl.FileServiceImpl.saveFile(FileServiceImpl.java:41)
- at org.sbezgin.p2016.services.file.impl.FileServiceImplTest.testSaveFolder(FileServiceImplTest.java:35)
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
- at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
- at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
- at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
- at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
- at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
- at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
- at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
- at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
- at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:254)
- at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:89)
- at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
- at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
- at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
- at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
- at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
- at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
- at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
- at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
- at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:193)
- at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
- at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
- @Transactional
- public class FileServiceImpl implements FileService {
- private BeanTransformer beanTransformer;
- @Override
- public AbstractFileDTO getFileByID(long fileID) {
- }
- @Override
- return null;
- @Transactional(propagation = Propagation.REQUIRED)
- public void saveFile(AbstractFileDTO file) {
- if (id null) {
- AbstractFile fileEntity = (AbstractFile) beanTransformer.transformDTOToEntity(file);
- user.setId(1);
- }
- public void setPermission(long fileD, PermissionDTO perm) {
- }
- @Override
- public void renameFile(long fileID, String newName) {
- }
- @Override
- public void deleteFile(long fileID, boolean recursively) {
- }
- @Override
- User user = new User();
- List<AbstractFile> rootFiles = fileDAO.getRootFiles(user);
- List<AbstractFileDTO> abstractFileDTOs = new ArrayList<>(rootFiles.size());
- rootFiles.stream().map(
- rootFile -> (AbstractFileDTO) beanTransformer.transformEntityToDTO(rootFile)
- );
- }
- @Override
- public List<AbstractFileDTO> getChildren(long folderID) {
- }
- @Override
- public List<AbstractFileDTO> getFilesByType(String javaType) {
- }
- return fileDAO;
- this.fileDAO = fileDAO;
- return beanTransformer;
- public void setBeanTransformer(BeanTransformer beanTransformer) {
- }
- public AbstractFile getFileByID(User user, long fileID) {
- }
- @Override
- public Folder getFolder(User user, long folderID) {
- }
- @Transactional(propagation = Propagation.REQUIRED)
- public void saveOrUpdateFile(User user, AbstractFile file) {
- file.setClassName(file.getClass().getCanonicalName());
- session.save(file);
- public void saveOrUpdateFiles(User user, List<AbstractFile> files) {
- }
- @Override
- public void deleteFile(User user, long fileID, boolean recursively) {
- }
- @Override
- public List<AbstractFile> getRootFiles(User user) {
- Query query = session.createQuery('from AbstractFile as file where file.ownerID = :ownerId and file.parentId is null ');
- List list = query.list();
- }
- @Override
- public List<AbstractFile> getChildren(User user, long folderID) {
- }
- @Override
- public List<AbstractFile> getFilesByType(User user, String javaType) {
- }
- private Session getSession() {
- }
- public SessionFactory getSessionFactory() {
- }
- public void setSessionFactory(SessionFactory sessionFactory) {
- }
- <beans xmlns='http://www.springframework.org/schema/beans'
- xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
- xmlns:context='http://www.springframework.org/schema/context'
- xmlns:tx='http://www.springframework.org/schema/tx'
- xmlns:aop='http://www.springframework.org/schema/aop'
- xsi:schemaLocation='http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd'>
- <bean name='dozer' />
- <bean name='beanTransformer'>
- <property name='beanMap'>
- <entry key='org.sbezgin.p2016.db.dto.file.FolderDTO' value='org.sbezgin.p2016.db.entity.file.Folder'/>
- </property>
- <bean name='fileService'>
- <property name='beanTransformer' ref='beanTransformer'/>
- <bean name='fileDAO'>
- <property name='sessionFactory' ref='sessionFactory'/>
- </beans>
- <?xml version='1.0' encoding='UTF-8'?>
- <beans xmlns='http://www.springframework.org/schema/beans'
- xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
- xmlns:context='http://www.springframework.org/schema/context'
- xmlns:tx='http://www.springframework.org/schema/tx'
- xmlns:aop='http://www.springframework.org/schema/aop'
- xsi:schemaLocation='http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd'>
- <context:property-placeholder location='WEB-INF/hibernate.properties' ignore-unresolvable='false'/>
- <bean>
- <property name='driverClassName' value='${jdbc.driverClassName}'/>
- <property name='username' value='${jdbc.username}'/>
- <property name='password' value='${jdbc.password}'/>
- <bean>
- <property name='packagesToScan'>
- <value>org.sbezgin.p2016.db.entity</value>
- </property>
- <props>
- <prop key='hibernate.dialect'>${hibernate.dialect}</prop>
- <prop key='hibernate.show_sql'>${hibernate.show_sql:false}</prop>
- <prop key='hibernate.format_sql'>${hibernate.format_sql:false}</prop>
- <prop key='hibernate.id.new_generator_mappings'>${hibernate.id.new_generator_mappings}</prop>
- <prop key='hibernate.hbm2ddl.auto'>${hibernate.hbm2ddl.auto}</prop>
- </property>
- <bean>
- <property name='sessionFactory' ref='sessionFactory'/>
- <tx:annotation-driven transaction-manager='transactionManager'/>
- </beans>
- jdbc.driverClassName = org.hsqldb.jdbcDriver
- jdbc.username = sa
- hibernate.dialect = org.hibernate.dialect.HSQLDialect
- hibernate.format_sql = true
- hibernate.hbm2ddl.auto = create-drop
- <dependencies>
- <groupId>org.hibernate</groupId>
- <version>5.0.7.Final</version>
- <dependency>
- <artifactId>spring-context</artifactId>
- </dependency>
- <groupId>org.springframework</groupId>
- <version>4.2.4.RELEASE</version>
- <dependency>
- <artifactId>spring-tx</artifactId>
- </dependency>
- <groupId>org.springframework</groupId>
- <version>4.2.4.RELEASE</version>
- <dependency>
- <artifactId>dozer</artifactId>
- </dependency>
- <groupId>mysql</groupId>
- <version>5.1.38</version>
- <groupId>javax.servlet</groupId>
- <version>3.0.1</version>
- </dependency>
- <dependency>
- <artifactId>mockito-all</artifactId>
- </dependency>
- <groupId>org.powermock</groupId>
- <version>1.5</version>
- </dependency>
- <groupId>org.powermock</groupId>
- <version>1.5</version>
- </dependency>
- <groupId>junit</groupId>
- <version>4.11</version>
- </dependency>
- <groupId>org.springframework</groupId>
- <version>4.2.4.RELEASE</version>
- </dependency>
- <groupId>org.hsqldb</groupId>
- <version>2.2.8</version>
- </dependency>
- <build>
- <plugins>
- <!-- current version -->
- <artifactId>hsqldb-maven-plugin</artifactId>
- default value for in memory jdbc:hsqldb:hsql://localhost/xdb
- -->
- <driver>org.hsqldb.jdbcDriver</driver>
- <port>9001</port>
- <username>sa</username>
- <validationQuery>SELECT 1 FROM INFORMATION_SCHEMA.SYSTEM_USERS</validationQuery>
- <executions>
- <id>start-hsqldb</id>
- <goals>
- </goals>
- <execution>
- <phase>post-integration-test</phase>
- <goal>stop</goal>
- </execution>
- </plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <version>3.3</version>
- <source>1.8</source>
- </configuration>
- </plugins>
- </project>
Prop Key= Hibernate.id.new_generator_mappings False /prop
When Hibernate applications are deployed on JBoss Enterprise Application Platform 6, the hibernate.id.newgeneratormappings property defaults to false. If there is not existing entities created in the database yet, consider changing hibernate.id.newgeneratormappings to true. Dec 27, 2018 Overview Suppose you have a Spring MVC application which has been running on Wildfly server. This application uses following features/configurations: It uses Spring annotations. It uses JPA and thus has entity manager configured in its XML configuration. I was getting the same error-“com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table ‘mylocaldb.hibernatesequence’ doesn’t exist”. Using spring mvc 4.3.7 and hibernate version 5.2.9, application is made using spring java based configuration, now i have to add the “hibernate.id.newgeneratormappings” property mentioned.