Questions tagged [hibernate]

22463 questions
1

votes
2

answer
107

Views

Saving Objects from an Iterated List

I'm currently workin' on a sales module using java+hibernate+oracle... I'm done with my order form in my jsp like this: I'm getting my parameters doing this: ArrayList idMercaderias = new ArrayList(); ArrayList cantidades = new ArrayList(); ArrayList precios = new ArrayList(); for (int k = 0; k < 10...
Felipe Rodriguez
1

votes
1

answer
657

Views

Is it possible to use Hibernate without foreign keys

One simple question if somebody may had an experience in this topic: Is it possible to use Hibernate (with full functionality) without foreign keys at the tables...? In my case i need to this because i want to reverse engineering a liferay database and entities, and in liferay the foreign key just m...
czupe
1

votes
4

answer
475

Views

How to use Hibernate Search without an underlying database?

Is it possible to use hibernate search features without using hibernate core for the database stuff? I want to create a Bean with standard Hibernate-Search annotations and store everything by hand for testing purposes (and I don't want to create the Hibernate Tables for testing). For a class to be a...
Martin Braun
1

votes
1

answer
10.4k

Views

spring hibernate optimistic locking issue

This is my Repository layer: class RepositoryImpl implements Repository{ @Override public Serializable saveOrUpdate(Object obj) { return getSession().save(obj); } @Override public Object get(Class refClass, Serializable key) { return getSession().get(refClass, key); } } This is my Service lay...
Prabhakaran
1

votes
1

answer
796

Views

Migrating Spring application from Postgres to Oracle: defining table's schema

FINAL EDIT The reason why I didn't see any logs is that I was using an old version of log4j. Hibernate hbm2ddl uses slf4j for logging and so all the logs were ignored by log4j 1. Now I upgraded to log4j2 that has a slf4j bridge and I see all the errors in the log. Godd new is that from here I can pi...
malavock
1

votes
3

answer
2.3k

Views

Issue with comparing two object in Hibernate

I have 2 methods. @Service @Transactional public class MyService { void myMethod() { Entity e1 = dao.get(1); e1.setName("NEW ENTITY NAME"); save(e1); } void save(Entity e) { Entity oldEntity = dao.get(1); oldEntity.getName().equals(e.getName()) // TRUE. Why? } } But in method save entities are not...
MyTitle
1

votes
1

answer
299

Views

Find domain object with multiple ID attributes?

How can I fetch a domain object that has multiple @Id attributes defined? class Test { @Id private String first; @Id private String second; } //how can I pass multiple IDs to find with entitymanger? em.find(Test.class, id);
membersound
1

votes
1

answer
45

Views

Illegal attempt to associate a collection with two open sessions -Dropwizard with Hibernate

I am using Hibernate and JPA in my dropwizard application to help with the CRUD operatons of my objects. Here is the method that throws the exception @RetryOnFailure(attempts = 5, types = {org.hibernate.exception.LockTimeoutException.class, org.hibernate.exception.LockAcquisitionException.class}, d...
user_mda
1

votes
1

answer
4.1k

Views

Hibernate findByExample with 'like'like behaviour on not null (string?) fields from the example

I'm using hibernate 4 and Spring 3. As the long title says, I need to create a method like this public list findByExample(MyObject exampleInstance){ Criteria crit = session.createCriteria(MyObject.class); Example example = Example.create(exampleInstance); crit.add(example); return crit.list(); } bu...
Gabber
1

votes
3

answer
10.5k

Views

Return SessionFactory Singleton object for Hibernate 4.3

I am using Hibernate 4.3. I am trying to get the SessionFactory object from a HibernateUtil class. I am trying to get only one SessionFactory object for entire application, i.e. Singleton object for application. Below is my current code, I want to make it Singleton class. HibernateUtil.java public c...
Mandar Pandit
1

votes
3

answer
5.7k

Views

Hibernate SQL Exception java.lang.StringIndexOutOfBoundsException: String index out of range

I am writing below query to get record for today date Session session = getSessionFactory().getCurrentSession(); DateTime todayAtMidnight = new DateTime().withTimeAtStartOfDay(); DateTime tomorrowAtMidnight = todayAtMidnight.plusDays(1); Query query = session.getNamedQuery("findUsersOrder") .setTime...
user3696143
1

votes
2

answer
1.8k

Views

Hibernate database connection error in Maven Dropwizard

I have been trying a Dropwizard project using Maven. I can run hello world programs. When I tried to run database program using Hibernate, I got an error like below when running the program using java -jar. default configuration has the following errors: * database.driverClass may not be null (wa...
Rajeesh V
0

votes
0

answer
2

Views

I would like to know the benefit of using hibernet Inheritance

I would like to know the benefit of using Hibernate Inheritance. What I do feel is still we can get the relational data by having our existing hibernet mapping say one-to-many or many-to-many. Why do we need this.
user1482725
1

votes
1

answer
5.9k

Views

could not set a field value by reflection setter of <class>

I have seen a similar question in this forum, here it is Mapping Value in Junction Table & hibernate.PropertyAccessException: could not set a field value by reflection setter I've applied the solution mentioned in this question but still I am facing the same problem. I don't know what am I missing....
meexplorer
1

votes
1

answer
1.6k

Views

hibernate - cascading type persist for many to many relationship

I have two classes Policy and Acl. They have a ManyToMany relationship in them. // Policy public class PolicyEntity { @Id @GeneratedValue(strategy = GenerationType.SEQUENCE) @Column(name = "POLICY_ID") private int policyId; @Column(name = "POLICY_NAME") private String policyName; @ManyToMany(casc...
Furquan Ahmed
1

votes
2

answer
6.1k

Views

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException… why?

I develop server using spring mvc and hibernate. So, I write my server program using Spring mvc and maven. However when I start my server program at tomcat server, Error occurs. That is things expected. so, I search using my error message. However I can't find answer. help me.... This is my servlet-...
Rect
0

votes
0

answer
34

Views

How to instance 2 different object with only one HTTP request (JSON file)

I made a database with Java Spring and Hibernate. There is an responsable entity and an account entity and they are linked with OneToOne relation. Here are my code : REST controller : @RestController @RequestMapping("/test") public class test { @Autowired private final ResponsableDBRepository respo...
Flo_H99
0

votes
0

answer
8

Views

I created a basic CRUD GUI with Hibernate, but I get “index out of bound exception”. What could be the problem?

Here is the GUI of my application with index out of bound error message: Here is the code for the search algorith: private void searchButtonActionPerformed(java.awt.event.ActionEvent evt) { try { String name = this.searchTextField.getText(); if (name.equa...
Fluellen
1

votes
1

answer
8.5k

Views

findBy with custom filter in PagingAndSortingRepository

I have an interface extending the PagingAndSortingRepository I have a custom find like : findJobByNameBySystemIdUserCompanyId(companyId, pageable) This works fine, now I want to introduce filtering, so I want to search (like) for string in the list. How can I achieve that? The search term could be...
victor
1

votes
4

answer
360

Views

Protect entity from cascade delete in Hibernate

Simple question: does anyone have any ideas how to protect some entity from being deleted via CascadeType.ALL in hibernate in runtime (may be with throwing a runtime exception)? Say, we have some entity: @Entity @Table(name = "FOO_ENTITY") public class FooEntity { ... } And I want to protect it from...
Andremoniy
1

votes
2

answer
379

Views

Temporarily disable grails autostamp

I have a grails job that is doing some processing on my data. This involves updating a title field after some string manipulations. I am trying to have the lastUpdated stamp not affected by the above process, as users will often sort by lastUpdated. Is there a way to temporarily disable autoTimesta...
Giannis
1

votes
2

answer
926

Views

How can i get Map object from Hibernate Query [duplicate]

This question already has an answer here: How to fetch hibernate query result as associative array of list or hashmap 2 answers Currently i am getting List of Object form Hibernate Query My code is: session.createSQLQuery("SELECT c.EMP_ID, COUNT(*) FROM employee c WHERE c.CITY=:someCity") List objL...
iTech
0

votes
0

answer
4

Views

JPA Join on multiple columns in OR condition

I have 3 entities and I want to make the following SQL query with a JPA CriteriaBuilder. SELECT * FROM record as a JOIN record_management as b ON (a.id_supervisor = b.id OR a.id_manager = b.id) JOIN user as c ON(b.id_user = c.id) WHERE a.id_company = 1 I try writing the following code but I cannot w...
samjackit
4

votes
1

answer
39

Views

Can I define different type for foreign key column from the parent table?

I need to connect to a postgreSQL database in a relation like in the code. The problem is in the database "id" in table "b" is "bigint" and "b_id" in table "a" is "integer", prod db is not in my control so i can't change it. "b_id" in "a" is not defined as foreign key, thats probably why postgre did...
1

votes
3

answer
686

Views

org.hibernate.PersistentObjectException: detached entity passed to persist: com.xptraining.model.Representative

Error Caused by: org.hibernate.PersistentObjectException: detached entity passed to persist: com.xptraining.model.Representative cart controller class @POST @Path(XpConstants.PLACE_ORDER) @Consumes("application/json") @Produces("application/json") public Status placeOrder1(Carts carts) { Representat...
Harshad_Kenjale
0

votes
1

answer
21

Views

Entity with two FK to the same entity

I am making an appointment system and have some problem with mysql structure and model structure. There will be two kinds of users (at least): customer and provider. Customers will be making appointments for choosen work with available provider for that work. Providers will be able to add themself t...
a4dev92
1

votes
1

answer
747

Views

java.lang.NoClassDefFoundError: org/springframework/orm/hibernate5/HibernateTransactionManager

I am trying to integrate spring with hibernate and I have spring-orm .4.3.6 jar file in my project.But still I am getting below error : java.lang.NoClassDefFoundError: org/springframework/orm/hibernate5/HibernateTransactionManager at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.C...
Naren
1

votes
1

answer
18

Views

LazyInitializationException even with @Transactional

Having a hard time getting a simple OneToMany mapped by the ManyToOne Entity to work when I go to fetch a user's comments. Other answers have suggested that you have to create the query yourself with the entityManager but that seems so horrible. Whats the point of an ORM if you can't even do somet...
b15
0

votes
2

answer
31

Views

Delete a row only into the join table

Question Is it possible to delete a row into a join table created by @ManyToMany annotation? Context With this schema : TAG TAGS_ARTICLES ARTICLE When a tag is removed from public Set tags (a list into ARTICLE class) corresponding rows into TAGS_ARTICLES is removed too, but not the tag into TAG tabl...
N. Lamblin
3

votes
1

answer
19

Views

Unable to lazily load JPA relationships

I'm working with Jhipster. I'm not being able to fetch Customers lazily. I have made a JDL like so... PROPERTY id ... CUSTOMER id ... CUSTOMER_PROPERTY id customer_id property_id value relationship OneToMany { Customer to CustomerProperty } relationship ManyToOne { CustomerPrope...
Bruno Miguel
1

votes
1

answer
45

Views

flyway migration on existing database results in “wrong column type encountered in column”

i have spring boot application that uses my database schema. Lets say i have non-empty schema with table APPLICATION_USERS defined as follows: create table AREA ( name NVARCHAR2(36) not null, id NUMBER not null ) now i wanted to add FlyWay to my application. I have defined in my application proper...
Akka Jaworek
1

votes
1

answer
37

Views

Spring Hibernate @Transactional clarifications

I got a lot of confusion about @Transactional annotation. 1) If I use just declarative approach, is it enough to mark my service class/methods as @Transactional, or should I create the configuration beans and properties as shown in this Baeldung article? 2) I need to use even programmatical appr...
4javier
0

votes
0

answer
5

Views

One to many doesn't update without a reference when setting only id instead of taking the object from DB first

Iam using Spring Hibernate with JPA. cascade=CascadeType.ALL and @Id @GeneratedValue(strategy = GenerationType.IDENTITY). I have two tables one is User the other is photos when I want to add a new photo do I need to go and take the User from the database and then set it as a user in the photo with p...
heyza22
0

votes
1

answer
13

Views

Hibernate Named native query giving the Exception as 'Invalid Column'

Altered the table(User) with salary column. but before Adding the salary field in the POJO it was worked fine. After that only I am facing the issue. Need solution to map exactly with the fields. package com.example.model; import javax.persistence.Entity; import javax.persistence.NamedNativeQueries...
Roshini
-1

votes
0

answer
5

Views

How to insert foreign key in jsp form to store it in the datebase?

this is the error that is appeared, when i submit the form https://i.imgur.com/FxKw7Bl.jpg
22mando
0

votes
0

answer
6

Views

How to model relationship tables as entities in Hibernate

I'm new to using spring and hibernate. I want to design the database according to this Schema Student, Class and School are Entities. There exists relationships studies_in(between Student and Class - one to one, with student_id and class_id as foreign keys) and belongs_to(between Class and School -...
Harsha Sridhar
0

votes
1

answer
12

Views

How to implement dao to get list without createCriteria() and get list with following properties?

I am implementing DAO in Spring-5, Maven Project with Hibernate 5, for getting list with offset and maxcount with the help of sessionFactory.getCurrentSession().createCriteria() but its now deprecated and i want to implement I want these three function to be in new method for what createCiteria() r...
user8963364
0

votes
0

answer
4

Views

Error: “could not get a field value by reflection getter of ”

Caused by: java.lang.IllegalArgumentException: Can not set java.lang.Integer field service.model.Setor.id to java.lang.String I tried changing the ID column type, it did not work. I researched other cases here in the community and other forums, but no have any case applied to my problem as a solutio...
Moézio Leivas
0

votes
1

answer
28

Views

Cant extract ResultSet, related to String as

Error messages in spring: : GenerationTarget encountered exception accepting command : Error executing DDL "create table category_class (category_name varchar(255) not null, primary key (category_name)) engine=MyISAM" via JDBC Statement : GenerationTarget encountered exception accepting command : E...
froffen
0

votes
0

answer
5

Views

Hibernate migration: Entities with Status.SAVING end up with NPE during session flush

I do hibernate upgrade in my application from 4.3.7 to 5.3.7 I started experiencing strange behavior during session.flush() operation. In one of my transactions, I have over 990 objects. All entities are versioned with optimistic locking (@Version). Some objects during flushing end up with null po...
Piotr

View additional questions