hibernate-5.x

Hibernate 5.2 get natural id properties from metamodel

醉酒当歌 提交于 2019-12-11 01:49:00
问题 Since SessionFactory#getClassMetadata(java.lang.Class) was deprecated, I am not able to use ClassMetadata. I would like to access to the following methods: org.hibernate.metadata.ClassMetadata#getNaturalIdentifierProperties org.hibernate.metadata.ClassMetadata#hasNaturalIdentifier According to the documentation, I should replace getClassMetada with EntityManagerFactory.getMetamodel(). However, the metamodel does not contain methods to get natural-id. I am using xml mapping for natural-id and

How to get Count in Hibernate 5 CriteriaBuilder with criteria condition

拟墨画扇 提交于 2019-12-11 01:13:42
问题 When I checked below code I got the count of all record. not condition wise. CriteriaBuilder builder = getCurrentSession().getCriteriaBuilder(); CriteriaQuery<Long> countQuery = builder.createQuery(Long.class); countQuery.select(builder.count(countQuery.from(ViewEmployees.class))); Long q1 = getCurrentSession().createQuery(countQuery).getSingleResult(); I want to get the count with criteria condition. like this code CriteriaQuery<ViewEmployees> query = builder.createQuery(ViewEmployees.class)

Hibernate 5 ImplicitNamingStrategy

一笑奈何 提交于 2019-12-10 18:56:42
问题 I want to use hibernate 5.x. With hibernate 5.x there are new interfaces for ImplicitNamingStrategy and PhysicalNamingStrategy . For a property name of an entity User I want to have a column name user_name in my database. I do not want to annotate every property with @Column(name="...") . I tried to write a custom ImplicitNamingStrategy but there is no way to get the name of the owning entity. public class MyNamingStrategy extends ImplicitNamingStrategyComponentPathImpl { @Override public

Hibernate 4 -> 5 migration: NamingStrategy changes, Tables not found

戏子无情 提交于 2019-12-10 12:55:25
问题 What i want to do I'm trying to migrate from WildFly 8.2.0 to WildFly 10.0.0 which means that i have (and want) to migrate from Hibernate 4.3 to Hibernate 5.0. Setup Java 8u40 Spring 4.1.9 SQL Server 2012 Wildfly 8.2.0 -> Wildfly 10.0.0 Hibernate 4.3.6 -> Hibernate 5.0.7 I have read the migration guide and i'm hit by the Naming Strategy changes. I have read many questions about this on SO, but mine seems a bit different. Hibernate complains that tables are not found: INFO [o.h.Version]

Migrating to Hibernate 5.x

拜拜、爱过 提交于 2019-12-09 19:24:30
问题 I am migrating my application to Hibernate 5 from Hibernate 3. We are using DatabaseMetadata class to get TableMetadata . Hence using TableMetadata object to get DB table column information like column size, type..etc. It seems in Hibernate 5 DatabaseMetadata class got deprecated (removed!). Are there any alternatives for DatabaseMetadata class in Hibernate 5? Or else how to get TableMetadata in Hibernate 5 env? 回答1: It got removed in 5.0 as we moved to a new approach to schema tooling.

hibernate 5.2 spring boot 1.5 integration without JPA

独自空忆成欢 提交于 2019-12-08 07:24:46
问题 I a using hibernate 5.2 with spring boot 1.5 version. I have used sessionFactory instead of entityManager. When I create a command line application by making the main class extend the CommandLineRunner, I am able to do insert and delete into my MySQL instance. But when I create a REST controller and send a post request, I get an exception that if related to JPA. I am not using JPA so why this exception ? The exception that is get is the following:- 10-11-2017 19:19:34.236 [http-nio-8089-exec

EntityManagerFactory must not be null after migrate to hibernate 5.2.6 in spring boot

白昼怎懂夜的黑 提交于 2019-12-08 02:56:29
问题 I using Hibernate in my Spring boot App after migrate from Hibernate 5.0.11 to 5.2.6.Final .i get EntityManagerFactory must not be null exception this is my codes My Hibernate Configuration @Configuration @EnableTransactionManagement public class DatabaseConfiguration { @Bean public HibernateJpaSessionFactoryBean sessionFactory() { return new HibernateJpaSessionFactoryBean(); } @Bean public HibernateTransactionManager transactionManager(@Autowired SessionFactory sessionFactory) {

Migrating to Hibernate 5

隐身守侯 提交于 2019-12-07 08:00:32
问题 I am migrating an application from Hibernate 4.3 to Hibernate 5.0.1-Final I use ImplicitNamingStrategyComponentPathImpl as my hibernate.implicit_naming_strategy with Postgres 9.4.4 and my company uses hibernate.hbm2ddl.auto = update for deployment ( I know it is a bad practice but cant help it) While the session factory initializes, it throws the below error. Apparently the generated alias is too long for Postgres. How do we go about this situation? I have tried assigning @Table(name=..)

Hibernate gives a strange ClassCast exception (using Transformers)

不问归期 提交于 2019-12-06 18:22:49
问题 This code: @Override public List<FactCodeDto> getAllFactsWithoutParentsAsFactDto() { String completeQuery = FactCodeQueries.SELECT_DTO_FROM_FACT_WITH_NO_PARENTS; Query query = createHibernateQueryForUnmappedTypeFactDto(completeQuery); List<FactCodeDto> factDtoList = query.list(); //line 133 return factDtoList; } calling this method: private Query createHibernateQueryForUnmappedTypeFactDto(String sqlQuery) throws HibernateException { return FactCodeQueries.addScalars(createSQLQuery(sqlQuery))

Getting “Another unnamed CacheManager already exists” error when running Hibernate 5 with my Junit 4 tests

天涯浪子 提交于 2019-12-06 13:55:40
问题 I recently upgraded to Hibernate 5.1.0.Final (with accompanying ehache) and am using Spring 3.2.11.RELEASE. Despite following the advice here -- Another unnamed CacheManager already exists in the same VM (ehCache 2.5), I'm seeing an error when running my JUnit tests. I have the following ehcache.xml file in my src/main/resources directory <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../config/ehcache.xsd" updateCheck="false"> <!-- This is a