天道酬勤,学无止境

hibernate

Spring Data DTO projection

We would like to use a DTO projection over the interface one, thus we created following DTO objects: PersonDto @Data @Builder @AllArgsConstructor public class PersonDto { private String name; private String email; private AddressDto address; } AddressDto @Data @Builder @AllArgsConstructor public class AddressDto { private String address; private String streetNumber; } A repository @Repository public interface PersonRepository extends JpaRepository<PersonEntity, Long> { List<PersonDto> findAllDtoedBy(); } However, when called we get the exception: Caused by: org.hibernate.hql.internal.ast

2021-06-14 17:05:52    分类:问答    hibernate   spring-data   spring-data-jpa

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

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), reference varchar references Sequence(reference) ) The objects look like (annotations are on the getter

2021-06-14 17:04:01    分类:问答    java   hibernate

Hibernate import.sql not found wherever I put it

I'm using a Spring MVC + JPA/Hibernate config over maven. When I deploy to Tomcat I expect Hibernate to execute an import.sql file but it doesn't matter where I put it or how I configure the path to the file, it never finds it. org.hibernate.tool.hbm2ddl.SchemaExport SchemaExport - HHH000227: Running hbm2ddl schema export org.hibernate.tool.hbm2ddl.SchemaExport SchemaExport - Import file not found: /META-INF/import.sql My configuration for Hibernate is, in Spring: <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> ... <property name=

2021-06-14 17:03:14    分类:问答    spring   hibernate   maven   tomcat   jpa

Retrieving a row number from within a specific group of rows using a self join in JPA

Given a table named rating in a MySQL database. +-------------+---------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+---------------------+------+-----+---------+----------------+ | rating_id | bigint(20) unsigned | NO | PRI | NULL | auto_increment | | prod_id | bigint(20) unsigned | YES | MUL | NULL | | | rating_num | int(10) unsigned | YES | | NULL | | | ip_address | varchar(45) | YES | | NULL | | | row_version | bigint(20) unsigned | NO | | 0 | | +-------------+---------------------+------+-----+---------+--------------

2021-06-14 16:44:38    分类:问答    hibernate   jpa   self-join

Getting Exception No Dialect mapping for JDBC type

I am new to hibernate and java. I'm trying to execute native sql query but I have been stuck. Can anyone can help me out or check where I'm doing mistake? My java code is : try { trns = session.beginTransaction(); String sql = "select principle,interest from salaryinfo where empid = " + selectedempid + ""; SQLQuery query = session.createSQLQuery(sql); List<Object[]> rows = query.list(); for (Object[] row : rows) { Salaryinfo si= new Salaryinfo(); si.setPrinciple(Float.parseFloat(row[0].toString())); si.setInterest(Float.parseFloat(row[1].toString())); sis.add(si); } Error Trace: Severe: org

2021-06-14 16:34:06    分类:问答    java   hibernate   jdbc

Spring Boot: The managed version is 1.3.2.RELEASE The artifact is managed in org.springframework.boot:spring-boot-dependencies:1.3.2.RELEASE

I create a skeleton application use Spring boot. This is my pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.lynas</groupId> <artifactId>SpringMVCHibernate</artifactId> <version>1.0-SNAPSHOT</version> <packaging>war</packaging> <name>SpringMVCHibernate</name> <description>SpringMVCHibernate</description> <parent> <groupId>org.springframework.boot<

2021-06-14 15:27:53    分类:问答    spring   hibernate   maven   spring-boot

How to delete a row in join table with JPA

I have the model below : an article can have some tags and a tag can be on some articles. So it is a many-to-many relationship with 3 tables : ARTICLE ARTICLE_TAG TAG When I delete a tag, I want to delete : the tag in TAG all relations between the tag and the articles tagged in ARTICLE_TAG But I don't want to delete the articles in ARTICLE of course. How can I do that ? I try this, but it doesn't work : Session session = HibernateUtil.getSessionFactory().getCurrentSession(); for (Article article : tagToDelete.getArticles()) { article.getTags().remove(tagToDelete); } session.delete(tagToDelete)

2021-06-14 13:50:14    分类:问答    hibernate   many-to-many   jointable   mappedby

flush mode changed in grails from AUTO to MANUAL

After upgrading my Grails project from 1.3.7 to 2.4.0 and after fixing various issues related to the new grails version, I realized that none of the changes done to any object would be persisted anymore (at all) except if save(flush:true) is called. With Grails 1.3.7 the default behavior when saving a domain instance using save() is that changes get persisted automatically, due to hibernate flushMode => FlushMode.AUTO. In Grails 2.4.0 this is not true anymore. The default flushMode of the hibernate session inside any controller action or service class is FlushMode.MANUAL. Things get even

2021-06-14 13:34:20    分类:问答    hibernate   grails   save   flush

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

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 embedded class. The problem is that the type signatures must only refer to other interfaces to satisfy the

2021-06-14 13:34:06    分类:问答    hibernate   jpa   persistence

Hibernate returns error “Class path must be set or restored default”

I am new to Java application based on Hibernate technology. I get some problems in installing my system. I am installed in my friends system. I installed JBOSS Tools (in that only Hibernate tools) in Eclipse Juno (Portable). I just copied that folder in to my system and I run the Eclipse.exe file and it runs smooth and I am trying to create new Hibernate Configuration file in hibernate perspective. But I got below error: Class path must be set or restored default

2021-06-14 13:32:16    分类:问答    java   eclipse   hibernate   eclipse-plugin