I have 3 entities in my Spring boot application. User,Item and Orders I want one Orders object to have multiple Items so, I used @OneToMany mapping in Orders class. This is my code: This is my Item.java file This is my Orders.java file Hibernate is generating 3 tables as I expected Item , Orders and Orders_Item from above code. Orders
Tag: hibernate
Can a Java hibernate/persistence entity have a related entity ID as well as the related entity?
Pretty simple setup, I have a building entity that belongs to an account. So the building entity looks like: (BaseEntity provides id, created and lastModified columns) I.e. The building has a name, the ID of the account it belongs to, and then the account entity that it belongs to. However, with this setup I’m getting errors when my Spring Boot
Using the concept of JPA, how to update table using data from another table?
FmoReorgGeo.java FMOReorgGeoServiceImpl.java FMOReorgGeoRepository.java ERROR LOG *I am trying to fetch data from reorgViewX and then updating FmoReorgGeo table. I am being able to fetch data correctly but when running update query I am getting error. The error says: Could not extract result set metadata; nested exception is org.hibernate.HibernateException: Could not extract result set metadata. I am using the concept of
Connecting 3 tables with hibernate / spring-boot
I have problem understanding how to connect 3 tables with spring-boot / hibernate. Tables are: Users, Technologies, Categories Every user has all of the 10 categories but inside this categories they can save one or more technologies. Each technology can be listed in several different categories. I have a code that works partially as for now instead referencing the table
SortedSet + Hibernate’s @SortNatural + Comparable not sorting elements when fetch from DB
I know similar questions have been asked before, I looked through them but still can’t figure out why in particulary this case sorting is not working. I have 2 Entities – Category and Transaction with relations OneToMany. Inside one category there can be many transactions and One transaction belongs to certain category. When I fetch the category from DB I
auto changing data with Hibernate
I have problem with Hibernate. I have next method: This method should assign user on task and send message to kafka consumer with TaskBeforeUpdate and TaskAfterUpdate. But I have problem when I try to assign user, my BeforeUpdateTask change all his fields to TaskAfterUpdate. And this dont work, but i dont know why he is change all values. Answer The
Column ‘foreign_key_id’ cannot be null
I have a rest api exposed via @RepositoryRestResource from spring-data-rest-api. When I try to give the json payload from Postman to create a User linked to an Organization, it complains that Column ‘organizationId’ cannot be null, when I clearly provided it in the json. Each user belongs to an organization, so it’s a many to one relationship. I want Java
Does Hibernate allow writing of String/Type Safe SQL?
Does Hibernate allow the writing of String/Type SQL , similar to Entity Framework /w Linq, where a person can write proper Sql, and any misspelled SQL Table, Column names will be shown at compile time instead of run execution time? Answer As requested I’m adding my comment as an answer. Id depends on how you are creating your query, If
Null pointer exception on autowired field in Hibernate Interceptor (classes are managed by Spring)
I use Spring Boot and Hibernate in my application and I get NPE trying to reach a service in my Hibernate interceptor. I don’t have any troubles injecting this comment service in other classes. What is wrong? The service I need: The interceptor: The configuration is just like that: P.S. When I try to inject the comment service via constructor
StackOverflowError while fetching OneToMany mapped entity in Spring Data Jpa
I have two entities that have bidirectional mapping. The entities are given below, I need to fetch all the customer entities along with its mapped accounts. My service code looks like this, But I am getting StackOverFlowError. The log is mentioned below, Can anyone help?? What am I missing here? UPDATE toString() and log updated. Couldn’t add the full log