Questions tagged [hibernate]

30921 questions
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
1

votes
0

answer
45

Views

When create a new Persistence Unit?

I'm developing a GEO based app using PostGIS and Hibernate and I'm stuck on persistence units. I have entities with and without GIS attributes. And my persistence.xml is this: java:jboss/datasources/PostgresDS entity.PersistentEntity.Account entity.PersistentEntity.Score java:jboss/datasources/Postg...
GabrielRado
1

votes
0

answer
117

Views

Hibernate Exception-Initial SessionFactory creation failed.org.hibernate.MappingException: Could not determine type for:

I hava a problem in the server side of my project. I used hibernate for this. There are three entities such as account,chat and chataccount. Account entity is shown below. I didn't use any annotation to getters or setters. @Entity public class Account { @Id @GeneratedValue(strategy = GenerationType....
Vidurajith Darshana
1

votes
1

answer
244

Views

exception when running jpa query with DTO and join fetch

I am trying to run a query with join fetch but I am also using DTO projection to improve performance but I am getting the exception below: org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list [FromElement{explicit,no...
1

votes
1

answer
34

Views

java list (used to convert bo objects to database objects)

i am getting error as type mismatch cant convert from void to list in below code.. please help me how to solve it? public static List convertBOTODOCreateRolebo(List role) { java.lang.reflect.Type targetListType = new TypeToken() {}.getType(); List roleboss =new ModelMapper().map(role, targetListTyp...
Sneha Raj
1

votes
1

answer
144

Views

What is the relationship between outer transaction and inner transaction?

I am new to Hibernate and when I am using transactions I met couple of questions. Previously, the situation is @Transactional Class A { methodA1(){ DOs = fetchDOsFromDB(); methodA2(DOs); } methodA2(DOs){ ClassB.methodB1(DOs); } } Class B{ @Transactional(propagation = Propagation.REQUIRES_NEW) method...
yilia
1

votes
1

answer
42

Views

Include code in getter while using Criteria + projection

I am having this getter in an Entity : public String getEmpType() { return empType == null ? 'EMP' : empType; } and I am using Criteria + projection in the Dao : Criteria criteria = session.createCriteria(Employee.class); criteria.add(Restrictions.eq('employeeKey',key)) .setProjection(Projections...
osama yaccoub
1

votes
0

answer
63

Views

Hibernate many to one partial composite foreign key

I have situation where i have to map partial composite key as foreign key for example, hibernate is it possible to map partial composite key as foreign key? class Employee { @embededId EmployeeId id; } class Mobile { @Id int mobId; @ManyToOne @JoinColumn(name='empId' referencecolumnname='empId') Emp...
Praveen Badiger
1

votes
0

answer
563

Views

Unique records on multiple columns in Spring Boot

I have for example 2 tables: Table 1: user userid titleid (Links to title table below) name surname Table 2: title titleid title User Entity class: @Entity @Table(name='user', uniqueConstraints={@UniqueConstraint(name='user_unique', columnNames={'titleid', 'name'})}) @NamedQuery(name='User.findAll'...
Quentinb
1

votes
1

answer
501

Views

Spring Data JPA - findAllBy query checks for null?

The documentation shows that findByLastnameAndFirstname equals to where x.lastname = ?1 and x.firstname = ?2. We know that in sql = NULL is always false. You have to use IS NULL. Let's say we have an entry firstname = 'First' and lastname IS NULL. I call this findByLastnameAndFirstname(null, 'First'...
Shawn
1

votes
1

answer
212

Views

hibernate jpa application suspends everytime I want to run it

I'm using Hibernate 5.2 with JPA 2.1 Library.Every time I want to run my application it doesn't stop - I have to stop it manually because it's still working. Records are being saved to the database correctly. These are my project files: Main.java /** * @param args the command line arguments */ publi...
JNDaniel
1

votes
1

answer
238

Views

Hibernate/JPA persist OneToMany objects with generated UUID's

I have been using Hibernate a lot but using Hibernate/JPA with UUID got me stumped a bit. I am using hibernate 5.2.12.Final. I have an object called TimePeriod with this mapping: @Entity(name = 'time_period') public class TimePeriod extends AbstractDomainObject { @OneToMany(mappedBy = 'timePeri...
Ivo Limmen
1

votes
1

answer
64

Views

HQl query to retrieve data from Pipe row

I had tried to fetch data which is returning as Array in oracle which is written in a function of oracle as pipe row. When i tried using native query like select ar_0th_element from table(fn_name(arg)). the above code works fine in native sql query. how to do the same thing using hql.
Muthukumar Raju
1

votes
0

answer
756

Views

Hibernate Infinite recursion in One-To-One relationship

I have a mid-size project that is using One-To-One and One-To-Many relationships. Days ago, I got an Infinite recursion in One-To-Many relationships, but I managed to fixed it with those two annotations: @JsonManagedReference and @JsonBackReference. Now I am facing the same error, but in One-To-One...
Stiliyan Koev
1

votes
0

answer
132

Views

JHipster: Login with email + password. Issue with cache

I have a problem with the cache when I login with email/password in my dev enviroment of a JHipster project. Here are the steps: In a new fresh project, I login with [email protected] user Go to account->settings and change the email to [email protected] and save the changes I logout and then I can login...
Paul
1

votes
0

answer
35

Views

Refresh/Access updated Entities outside the transaction in Spring

I am spawning a newSpring transaction inside a readonly Spring transaction. The new transaction is creating an entry in DB. After coming out of the new transaction I am not able to fetch the data in the readonly transaction, though the entry has been created in the DB at that point. Interface A { @T...
nikhilsuri
1

votes
1

answer
212

Views

Why does hibernate save two @OneToMany lists in one table?

Imagine having following simplified code using Hibernate and JPA: @Entity class C { @Id @GeneratedValue public long id; } @MappedSuperclass abstract class A { @Id @GeneratedValue public long id; @OneToMany(cascade = CascadeType.ALL) public List list1; @OneToMany(cascade = CascadeType.ALL) public Lis...
Dracam
1

votes
2

answer
117

Views

How do I write a Controller class in Spring Boot for many Databases?

I have multiple databases (MySQL and a 4 NoSQL databases). The service classes all implement a CustomerServiceClass for CRUD-operations. This is how my Controller Class looks: @RestController @RequestMapping('/customer') public class CustomerController { @Autowired CustomerService customerService; p...
heythere
1

votes
2

answer
72

Views

Grails GORM - return count of objects who's array property > 0

Consider the following; class Person { int id String name static hasMany = [cars : Car] } class Car { int id String brand static belongsTo = Person static hasMany = [owners: Person] } The above will result in a person_cars join table. All I'm trying to find out is if there are any entries in that ta...
dre
1

votes
1

answer
198

Views

Getting entity from table without having primary key in Hibernate

I'm currently working on a project where I'm trying to get a list of enities from table which does not have a primary key (dk_systemtherapie_merkmale). This table is 1:n related to another table (dk_systemtherapie). See the screenshot for the table structure. When getting an entry for dk_systemther...
Sara Klüber
1

votes
1

answer
98

Views

Hibernate- Session object is NULL

I am new in back-end development. I am trying to develop Spring rest web API by use of annotation. For that first i initialize our classes. I am getting null for session object. public class FordonWebAppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { @Override protected Cl...
DJhon
1

votes
3

answer
85

Views

Hibernate join two entities

i really don't know what actually my problem is. I have two models in my Project. model-package Ansprechpartner Lieferant Ansprechpartner.java @Entity @Table(name = 'ANSPRECHPARTNER') @EntityListeners(AuditingEntityListener.class) @JsonIgnoreProperties(value = {'anlageAm', 'updatedAt'}, allowGetters...
Adel
1

votes
0

answer
48

Views

Hibernate JTA with bitronix and without JNDI

Is it possible to configure Hibernate without JNDI and not using Spring. persistence.xml requires jta-data-source property which takes JNDI of the data source.
l a s
1

votes
0

answer
187

Views

Hibernate: “no type name” with “AttributeConverter” on Map

I have this: @Column @Convert(converter = MyMapConverter.class) private Map temp; MyMapConverter is a simple JPA-AttributeConverter: @Converter public class MyMapConverter implements AttributeConverter { @Override public String convertToDatabaseColumn(HashMap attribute) { return attribute.toString()...
nimo23
1

votes
1

answer
1.2k

Views

JPA repository: list of objects associated to @Entity is empty when Entity is returned using findAll()

I am writing a test for a webservice that uses hibernate, JPArepository and a mysql database. Everything works well there, data is preloaded into the database and can be retrieved correctly (when the test is not used), however the test fails. The test uses a H2 in memory database. It compromises of:...
bekimarton
1

votes
0

answer
132

Views

Hibernate OneToMany in MappedSuperclass fails with Null Constraint Violation

Based on Why does hibernate save two @OneToMany lists in one table? Imagine having following simplified code using Hibernate and JPA: @Entity class D { @Id @GeneratedValue public long id; } @MappedSuperclass abstract class A { @Id @GeneratedValue public long id; @OneToMany(cascade = CascadeType.ALL)...
Dracam
1

votes
0

answer
65

Views

JPA @Convert in @Embeddable triggers unnecessary delete insert

We have the following JPA entities: @Entity @Table(name = 'T_PRIZE') public final class Prize { @Id @Column(updatable = false) private long id; @Embedded private Target target; } @Embeddable public final class Target { @ElementCollection @CollectionTable(name = 'T_CUTOFF', joinColumns = @JoinC...
SetNug
1

votes
0

answer
118

Views

Unable to generate property of type JSON using hibernate reverse engineering

I am using MySQL 5.7 inno DB and have a DB table with one column of type JSON. When i use hibernate reverse engineering to create POJOs, the entity java class is created for the table but the property type is Character. How do i get JSONObject or String type property for JSON column using hibernate...
Sid D
1

votes
0

answer
58

Views

How to create a custom implementation for Hibernate session

While investigating one issue with Hibernate, I want to make an experiment and change the default implementation of hibernate session (SessionImpl.java). Actually, I only want to comment out a couple of lines. One option to do that is to change source code and build custom version of Hibernate, but...
Mikhail Chibel
1

votes
0

answer
46

Views

Hibernate Tools Annotation Exception: Wrong number of columns

I have this java generated classes from a MySQL database using Hibernate Tools and I'm having a Annotation Exception: org.hibernate.AnnotationException: A Foreign key refering pt.sicad.model.Wfatividade from pt.sicad.model.Wfhistoricoatividade has the wrong number of column. should be 7 The generate...
Nuno Pereira
1

votes
1

answer
47

Views

How Hibernate match entity in one-to-one relation, despite of absence of a foreign Key?

i am still learning hibernate ORM. I have created 2 entities student and address.The realtion between them is one to one bidirectional.But when i check the db i found 3 tables :Student,Address and hibernate_sequence(in which an int attribute called next_val is registered ). Those are the table st...
fbm
1

votes
3

answer
937

Views

Disable Spring Boot HibernateJpaAutoConfiguration but still getting a related error

@SpringBootApplication(exclude = { HibernateJpaAutoConfiguration.class, JndiConnectionFactoryAutoConfiguration.class, XADataSourceAutoConfiguration.class, JndiDataSourceAutoConfiguration.class, ...) like code above, I disable pretty much Auto Configuration Classes provided by Spring Boot, because I...
EthanZhang
1

votes
1

answer
43

Views

ManyToMany on same Entity with field from MappedSuperclass

I would like to create ManyToMany relationship with same table on both side. It should represent friendship between two users. I have now User class: @Entity @Table(name = 'Users') public class User extends BaseObject implements UserDetails { //example of others relationship private Set posts; @OneT...
Sk1X1
1

votes
0

answer
24

Views

SqlGrammerException in Hibernate program

When I insert or save only one record to MySQL, it works fine. But when I insert more than two records using create property (notupdate), it throws an SqlGrammerException exception. The following is the code: package com.aartek.DTO; public class UserDTO { private int id; private String firstName,...
suyash sahu

View additional questions