hibernate

hibernate @Entity on inner class only (top level class is not an @Entity)

不打扰是莪最后的温柔 提交于 2021-02-07 18:46:56
问题 I would like to persist inner class into database. But it dosnt work. Is there possibilty to do that? Or should i put that inner class into new plain file? Now I am getting an error [IllegalArgumentException: Unknown entity: models.foo$bar] My class file: package models; public class foo { @Required public String report; @Required public String reportType; @Entity public static class bar{ @Required public int year; @Required public int month; public void toDataBase() { JPA.em().persist(this);

org.hibernate.criterion.Example use with CriteriaQuery

主宰稳场 提交于 2021-02-07 18:18:17
问题 I have following code that I need to refactor for use in hibernate 5. This includes removing every deprecated call. public List<T> findByExample(T example, String... excludeProperty) { Criteria crit = session.createCriteria(T.class); Example ex = Example.create(example); for (String exclude : excludeProperty) { ex.excludeProperty(exclude); } crit.add(ex); return crit.list(); } Since createCriteria is deprecated I was going to replace it with getSession().getCriteriaBuilder().createQuery(Foo

DAO and Service Layer with hibernate

痞子三分冷 提交于 2021-02-07 18:17:44
问题 im in trouble with implemenetation of a service layer, i think i did not understand this concept very well. In a DAO implementation i can write all CRUD logic for a specific technology and entity (for example hibernate and User table), and in a service layer we use a DAO for all data operation for the entity in DAO (like getUser, loginUser, etc..) is this ok? If this is ok i have a simple question, can i handle database connection (or in case of hibernate, session and transaction) within

spring jpa nested projection generating incorrect query

孤街浪徒 提交于 2021-02-07 13:39:29
问题 Lets consider these entities @Entity public class Room{ @Id private Integer id; private String number; private String floor; @ManyToOne private RoomType roomType; // Setters & Getters } @Entity public class RoomType{ @Id private Integer id; private String name; private String description; private Boolean enabled; // Setters & Getters } And also this interface for projection alongside repository class public interface RoomList{ public Number getId(); public String getNumber(); public RoomType

spring jpa nested projection generating incorrect query

删除回忆录丶 提交于 2021-02-07 13:36:47
问题 Lets consider these entities @Entity public class Room{ @Id private Integer id; private String number; private String floor; @ManyToOne private RoomType roomType; // Setters & Getters } @Entity public class RoomType{ @Id private Integer id; private String name; private String description; private Boolean enabled; // Setters & Getters } And also this interface for projection alongside repository class public interface RoomList{ public Number getId(); public String getNumber(); public RoomType

Hibernate failing by prepending fully qualified class name to property name on ManyToMany association

安稳与你 提交于 2021-02-07 13:15:55
问题 I'm trying to map two objects to each other using a ManyToMany association, but for some reason when I use the mappedBy property, hibernate seems to be getting confused about exactly what I am mapping. The only odd thing about my mapping here is that the association is not done on a primary key field in one of the entries (the field is unique though). The tables are: Sequence ( id NUMBER, reference VARCHAR, ) Project ( id NUMBER ) Sequence_Project ( proj_id number references Project(id),

Hibernate failing by prepending fully qualified class name to property name on ManyToMany association

狂风中的少年 提交于 2021-02-07 13:12:59
问题 I'm trying to map two objects to each other using a ManyToMany association, but for some reason when I use the mappedBy property, hibernate seems to be getting confused about exactly what I am mapping. The only odd thing about my mapping here is that the association is not done on a primary key field in one of the entries (the field is unique though). The tables are: Sequence ( id NUMBER, reference VARCHAR, ) Project ( id NUMBER ) Sequence_Project ( proj_id number references Project(id),

Hibernate and JPA - Error Mapping Embedded class exposed through an interface

一笑奈何 提交于 2021-02-07 12:57:15
问题 We have a set of interfaces, used as an API, and referenced from other modules. A set of concrete implementations of those interfaces, private to the "main" app module. These classes carry a number of annotations (JPA as well as XStream for XML serialization). I've run into a problem. We have a user class which had a number of fields within it related to location. We'd like to roll those up into an Address class. We want the data (for now) to remain in the same table. The approach is an

Continue with transaction after exception - JPA

ぃ、小莉子 提交于 2021-02-07 12:40:39
问题 I am using JPA with Spring. I am trying to do batch import. If there is problem with batch import then I would like to insert individually, and if this fails also then I would like to save to duplicates table. I wrote a logic for this but I get this error everytime: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly Mine setting for JPA are like this: @Bean(name = "dataSource", destroyMethod = "") public DataSource

How to configure hibernate logging using log4j2.xml?

筅森魡賤 提交于 2021-02-07 12:15:31
问题 I recently switched to Apache log4j2, and still can not find a way to configure hibernate logging using log4j2.xml. Because I can not find a way around this problem I still use log4j.properties file explicitly for hibernate. This is not the best solution since my log4j2.xml uses JPA appender (writes logs to db). I do not want to write separate logic for hibernate. Is there a way to configure hibernate logging using log4j2? 回答1: As suggested in https://issues.apache.org/jira/browse/LOG4J2-172