Questions tagged [hibernate]

30954 questions
0

votes
2

answer
21

Views

JPA: How to map only one property from another entity

Let's say I have two entities: @Entity public class Phone { @Id private Long id; private String number; } @Entity public class Person { @Id private Long id; private String name; } The relationship between a person and a phone is one to one. How could I access only the phone's number in the Person en...
Fabian Mendez
1

votes
1

answer
2k

Views

Unable find Entity .. while trying to save data

I'm getting this exception when I try to save a topic with a message: nested exception is javax.persistence.EntityNotFoundException: Unable to find mypackage.model.Message with id fb8d39ea-0094-410d-975a-ea4495781422 Here is the model : @Entity public class Topic { @Id private String id; private St...
FakeLion
1

votes
1

answer
684

Views

How to use postgis type Geography with spring-boot and postgresql?

I have a Spring-boot project with hibernate. Also, I have a postgresql database with postgis extension. I really want to make use of the postgis extension geography type. Unfortunately, it seems that Hibernate does not support the geography type, only type geometry, which is unsufficient for my need...
Ville Miekk-oja
1

votes
2

answer
2k

Views

how to do a JOIN FETCH in jpa criteria

I am trying to translate the query below to criteria api. SELECT er from ereturn er JOIN FETCH product_item pi ON pi.ereturn_id = er.id WHERE pi.status = 'RECEIVED' To something like this: CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery criteria = builder.createQuery( Ereturn.class...
0

votes
0

answer
13

Views

Hibernate Could not fetch the SequenceInformation from the database but still works fine

I have 2 entities User And UserRole. if I make UserRole entities like this with a role as id everything works fine but this is bad because I can't have 2 different users with the same role: @Entity @Table(name = 'USER_ROLES', uniqueConstraints = @UniqueConstraint( columnNames = { 'ROLE', 'USERNAME'...
Patches Joe
1

votes
2

answer
76

Views

What is difference between @Transactional(rollbackFor = Exception.class) and @Transactional(propagation=Propagation.REQUIRED)

@Transactional(rollbackFor = Exception.class) public void foo1() { `/**Some Code**/` } @Transactional(propagation=Propagation.REQUIRED) public void foo2() { `/**Some Code**/` }
Rajesh Gupta
1

votes
3

answer
317

Views

Does Hibernate has a specific condition for naming columns that start with the same letter?

I'm using spring boot and jpa hibernate to create some tables in my database but it throws a weird exception which i don't really understand. @Entity public class Option { @Id @GeneratedValue(strategy = GenerationType.AUTO) private int id; private String marca; private String model; private String a...
Truica Sorin
1

votes
1

answer
226

Views

ORM Who can generate script dynamically

So basically I was checking working of hibernate, as well evaluated ORMs JOOQ. JPA is main de-facto standard for all java based ORM implementations more or less. I am not saying they are not perfect or good but my problem is like I have found many issues and hick-ups while using various options prov...
0

votes
1

answer
34

Views

ArrayList with more 10 items saved not ordered to DB

I receive List dtos with 14 MyDto and try to save it to the database. I receive List loop dtos and on each step: 2.1 -> map MyDto to MyEntity 2.2) -> save and flush MyEntity to DB I expect 14 rows in DB, saved in the order in which I saved. For example: row0 row1 row2 row3 row4 row5 row6 row7 row8...
ip696
0

votes
1

answer
22

Views

JPA returning a nested object after creation - 500 Internal Server Error

I have my main object: @Data @Entity @EqualsAndHashCode(callSuper = false) @Table(name = MAIN_OBJ) public class MainObj { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = 'MAIN_OBJ_ID', unique = true, nullable = false) private Integer manObjId; @ManyToOne @JoinColumn(name = 'SUB_OB...
canpan14
1

votes
1

answer
2.2k

Views

how to write query in hibernate

I have one table, User, and in that table, I have 3 columns: id name email I want to retrieve a name for a particular email by passing the email id; how would I write that hibernate query?
DJ31
0

votes
1

answer
55

Views

Cannot load connection class because of underlying exception: com.mysql.cj.exceptions.WrongArgumentException

Here is my code: import java.sql.Connection; import java.sql.DriverManager; public class TestJdbc { public static void main(String[] args) { String jdbcUrl = 'jdbc:mysql://localhost:3306?hb_student_tracker?useSSL=false&serverTimezone=UTC'; String user = 'hbstudent'; String pass = 'hbstudent'...
macmar22
1

votes
2

answer
6k

Views

error: org.hibernate.PropertyNotFoundException: no appropriate constructor in class: com.a.offering.dto.SellerDetailsDto

I am using following query String queryString = 'select NEW com.h.offering.dto.SellerDetailsDto(p.productId,p.sellerId, p.sellerSku, p.sellPrice, ' + 'p.transferPrice, p.sellerMRP,p.aCommission,p.baseShippingFee,p.addnShippingFee, ' + 'p.propogationLevel,p.propogationValue,a.warehouseName,a.quantity...
Aashish Katta
1

votes
1

answer
11

Views

How to make JPA @query work with projection that has another projection in it

I'm trying to get projections works on @query in JPA with joined columns as an another project as well. Say, I have 2 entities: course and student and student can have many courses and the foreign key is on the course table: student(id, name, email, age, grade, uuid) course(id, name, uuid, student_i...
Chong Liu
1

votes
1

answer
745

Views

Reference existing data when deserializing Java objects?

My object graph consists of Hibernate entities. Now most of the objects don't exist in the new database. However some do. So my object is like this: Class MyObject{ Set bset; Set cset; } The items in bset need to be instantiated and persisted after deserialization. However, the items in cset alrea...
Osman
0

votes
0

answer
16

Views

Hibernate + Spring boot 2: Not checking the default schema

I am running a Spring Boot app with Hibernate. I have the following properties in my 'application.properties' to load a Mysql Datasource and set Hibernate properties. But When I run Integration tests with the following properties, Hibernate tends to check 'information_schema' as default schema and n...
Abhi.G
0

votes
0

answer
5

Views

Spring db config with 2 data sources - the second connection throws HibernateException

I'm working on a Spring project that requires 2 data sources. One is to save user details and the others are to save product's information and other processes. I defined the database configuration as follow: @Value('${caffein.datasource.url}') private String APP_DB_URL; @Value('${caffein.datasource....
Trung Bún
0

votes
0

answer
2

Views

How to save a domain with a hasMany property in gorm-hibernate

I have a User with hasMany UserRoles but when i try to save a User and addToRole there is a validation error during save i cant understand why. class User ... { static hasMany = [roles:UserRoles] } then i have a domain UserRoles class UserRoles ... { Roles role static belongsTo = [user: User] User...
Tarro Eso
1

votes
3

answer
2.9k

Views

Criteria query for unidirectional one-to-many relationship

So, I have the following entities: @Entity public class Supplier { @Column(name = 'SUPPLIERID') private BigInteger supplierId; @OneToMany @JoinColumn(name = 'ID_SUPP', foreignKey = @ForeignKey(name = 'fk_POIS_SUPP')) private List posList; ... } @Entity public class POS { @Column(name = 'POSID') priv...
Daniel Rusev
1

votes
1

answer
3.2k

Views

NoSuchMethodError during validator test (javax.el 3.0.0)

I try to test validator (hibernate-validator 5.1.3.Final) in spring context. If object is valid test is OK. But if object has invalid fields the error is java.lang.NoSuchMethodError: javax.el.ExpressionFactory.newInstance()Ljavax/el/ExpressionFactory. Validator works correctly on the tomcat 8.0 ser...
Dmitriy Kozlov
0

votes
0

answer
5

Views

How do I create a lookup table in my application using JPA and Hibernate?

I have an application that uses JPA and Hibernate. I have an entity called Person that has several fields that I would like to use lookup tables for. For example, there is gender, which [I believe] should look like this: @Entity @Table(name = 'genderLookup') @EntityListeners(AuditingEntityListener.c...
Brian
1

votes
1

answer
880

Views

How to dereference old Wildfly 9.0.1 deployment artifacts of Spring MVC app built with intelliJ-IDE?

I'm using intelliJ-IDE-14 to create a SpringMVC project named app which was initially being deployed to JBoss Wildfly 9.0.1.Final as app.war Here's the step by step scenario leading up to my issue; After finishing project config to utilize Maven | Spring | Hibernate | Wildfly | Velocity, then I made...
CodeBurner
0

votes
0

answer
21

Views

Hibernate differente method name as field

Is it possible that hibernate use a getter with a different name as the field? .... private ComplexObject test; @Access(AccessType.PROPERTY) @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true) @JoinColumn(name = 'number_format') public ComplexObject getSomeStuff() { .... return test; } ......
Kev
0

votes
0

answer
5

Views

Hibernate Criteria Query to use MySQL REPLACE and CONCAT functions

Trying to replicate the following MySQL query in Hibernate using CriteriaBuilder. This query adds first and last name, removes all whitespaces in between and search for results that matches the given string. select * from users where replace(concat(first_name, last_name), ' ', '') like 'jamesbon%';...
Vijay Nandwana
1

votes
3

answer
1k

Views

How do you programmatically generate a Hibernate JPA schema?

I'd like to use the Hibernate/HBM2DDL schema generation as a starting point for managing my application's SQL schema using a tool like Liquibase or Flyway. To assist with that, I need a small utility in my project that I can run that will print out the auto-generated schema. With older versions or H...
Karl M. Davis
1

votes
3

answer
73

Views

Unindentified SQL error syntax with SpringBoot and JPA

The compilation of my SpringBoot app fails to create a database. Caused by: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'read bit, releaseDate date, primary key (id)) engine=In...
Charles Julien
1

votes
2

answer
313

Views

Validate schema programmatically using hibernate

In mose projects the way to run your java app with schema validation is with that configuration (when using spring): spring.jpa.hibernate.ddl-auto=validate I ran into a problem that I need to validate my schema at a specific times during running, is there any way to implement that? I saw that hibern...
Daniel Taub
1

votes
2

answer
44

Views

Spring data jpa @Query - Cannot create an “AS” alias for a result map

I map the result of the following JPQL-Query directly to a SpecialCustomDto object instead of the used javax.persistency entity object MyEntity. But I do not know, how to access the COUNT(DISTINCT e.attributeB), which will be mapped to the SpecialCustomDto. This is the query. @Repository public inte...
git-flo
0

votes
0

answer
3

Views

How can I (if I can) extend a composed repository?

I am trying to give a Generic Parrent repository to all my 'per aggregate root' repositories which I can later use polymorphically. I have composed a parent 'composed repository'. Which is to be implemented by other specific Repositories. @Repository public interface ZoneNameJpaRepository extends Ge...
Aditya Kumar
1

votes
1

answer
2.5k

Views

Java TIMESTAMP has trailing zeros, how do I remove?

I'm using Java with hibernate and am in the early stages of learning how everything works. I'm getting there slowly but I have had some trouble with dates in Java. My current problem is that when I get a timestamp from a MySQL database it seems to have a load of extra zeros on the end. When I pass t...
diggersworld
1

votes
2

answer
843

Views

Is it possible to use 'index' as a column name in sqlite?

Is it possible to use index as a column name in sqlite? When i try to execute this query, it is generate with hibernate/jpa: select metadatait0_.id as id25_, metadatait0_.guid as guid25_, metadatait0_.index as index25_, metadatait0_.library_section_id as library7_25_, metadatait0_.metadata_type as m...
cremersstijn
0

votes
0

answer
13

Views

Hibernate SQL command not properly ended

I can not understand why hibernate can not execute this query on Oracle 12c database . SELECT * FROM T_MESSAGE m inner join T_METADATA smj on smj.C_ID = m.F_SYSTEM_METADATA_JSON inner join T_MESSAGETHREAD mt on mt.C_ID = m.F_MESSAGE_THREAD inner join T_EXCLUDEDUSER exu on exu.F_MESSAGE_ID = m.C...
mah454
1

votes
1

answer
3.4k

Views

Using a ParameterExpression as part of the In clause

I would like to use a parameter expression as part of an in clause. I would like to query for a list of Foos that have a Bar that is in a set of Bars. Is this possible? Foo // Join, ManyToOne Bar getBar() Query ParameterExpression barParameter; void setup() { CriteriaBuilder builder = ... CriteriaQ...
Craig Swing
1

votes
1

answer
51

Views

Creating JSON Objects from Relational DB JPA/Hibernate Queries

I have a relational DB accessed with JPA/Hibernate in a Spring web app. I have a lot of Ajax queries where the relational results need to be translated into JSON objects. Is there a simple solution to convert something like this, from a Relational JPA query, to the below? Result [ { id: event-..782,...
gene b.
1

votes
1

answer
87

Views

How to map Map<String, MyValueObject> with xml in jpa?

To decouple my domain model from persistance mechanism, I'm using XML to config mapping from my domain model to db entities. I have this entity: public class Tenant { long id; Map authApps; ... } And this value object: public class AuthApp { String authCode; int durationInDays; ... } The value objec...
S.min Chen
1

votes
1

answer
58

Views

Save data into MySQL DB using Hibernate @ManyToOne relationship [duplicate]

This question already has an answer here: How to use @Id with String Type in JPA / Hibernate? 3 answers Edited (not exact duplicate of How to use @Id with String Type in JPA / Hibernate?) Reasons: At the time, the error I was getting was this: org.hibernate.id.IdentifierGenerationException: Unknown...
Adrian Flores
1

votes
2

answer
35

Views

Using identifiers and values from other places in a Spring CrudRepository

I'm learning how to extend Spring's CrudRepository interface to create a repository for an entity. But I'm having trouble implementing more complicated queries that use values that aren't hard-coded. Here's a contrived example. The HQL is not valid, but it shows what I'm trying to do: import mypa...
J-bob
1

votes
0

answer
45

Views

Hibernate criteria query not giving complete resultset

I'm struggling to create a Hibernate criteria query to fetch all the data as follows I need a list of all appointments in a chamber but only one appointment comes in every chamber. public static List getChambersInfoOfDoctor(Long id) { print('Finding chambers of doctor: ' + id); List chambers = new A...
Ameer Moaaviah
1

votes
1

answer
60

Views

How do I refactor hibernate entities?

My use case is as follows: I've inherited a project that is using hibernate. The entity I'm focused on right now is, for the purposes of this exercise, closed to modification. The object of the exercise is to replace the use of the legacy entity with an unrelated implementation that is better suit...
VoiceOfUnreason
1

votes
1

answer
82

Views

Hibernate materializing non-existing Entity

We have an odd situation here, where Hibernate tries to materialize an entity, which is not there. We have two entities, A and B, roughly like this: public class A { ... @Id @NotNull @Column(name = 'aId') private int id; @OneToOne(mappedBy = 'a', cascade = CascadeType.PERSIST) @OptimisticLock(exclu...
Jonathan

View additional questions