jpa

@OneToMany relationship does not save the primary key of the parent in the children tables

北慕城南 提交于 2021-01-27 19:11:11
问题 Let there be three JPA Entities. A Person and two one-to-many relations to it. When I'm trying to save the Person AD_P_ID and AC_P_ID foreign keys are always null. The expected value for these fields is the person Id. What am I doing wrong? Person.java: This contains one to Many relationships with Account and Address Entity classes: @Entity @Table(name = "A2C_PERSON") class Person implements Serializable { private long id; private List<Account> acs; private List<Address> ads; @OneToMany

Is it possible to use a Enum-Method in a QueryDSL query

Deadly 提交于 2021-01-27 19:05:56
问题 I have an entity type that contains an enum field. I use a JPA 2.1 AttributeConverter to map enum instances/values to a database column. The Enum values contain additional information I'd like to use in a QueryDSL query as if that information would be stored in the database. Example: A message entity that contains a messageType. The type is a enum value. The enum determines if the message is global or not. In the database, the enum is represented as an int-value. The information if global or

Caused by: org.hibernate.MappingException: Could not determine type for: com.fasterxml.jackson.databind.JsonNode

帅比萌擦擦* 提交于 2021-01-27 18:45:40
问题 I am trying to use javax.persistence.* to auto create Table by uesing @Entity. Here is some problem. Is there anyway to convert the JsonNode to String By use Annotation. edit: the Jpa is Spring-Data-Jpa and the JsonNode is fasterxml.jackson 回答1: You cannot use a JsonNode on entity column using Spring Data Jpa, You must use String and in another class you can write a method which converts string to Json (a reverse Jason to string) format and Resolved! 回答2: Annotate your Json property with

Eclipselink - @CascadeOnDelete doesn't work on @OneToOne relations

故事扮演 提交于 2021-01-27 18:17:20
问题 I have two relations in my class: @OneToOne(mappedBy = "poi", cascade = { CascadeType.ALL }) @CascadeOnDelete protected PoiDescription description; @OneToMany(mappedBy = "poi", cascade = { CascadeType.ALL }) @CascadeOnDelete protected List<PoiAdditional> additionals = new ArrayList<>(); In my generated DDL (for postgres) I becomes: ALTER TABLE POI_DESCRIPTION ADD CONSTRAINT FK_POI_DESCRIPTION_POI_ID FOREIGN KEY (POI_ID) REFERENCES POI (ID) ALTER TABLE POI_ADDITIONAL ADD CONSTRAINT FK_POI

Eclipselink - @CascadeOnDelete doesn't work on @OneToOne relations

时光总嘲笑我的痴心妄想 提交于 2021-01-27 18:05:27
问题 I have two relations in my class: @OneToOne(mappedBy = "poi", cascade = { CascadeType.ALL }) @CascadeOnDelete protected PoiDescription description; @OneToMany(mappedBy = "poi", cascade = { CascadeType.ALL }) @CascadeOnDelete protected List<PoiAdditional> additionals = new ArrayList<>(); In my generated DDL (for postgres) I becomes: ALTER TABLE POI_DESCRIPTION ADD CONSTRAINT FK_POI_DESCRIPTION_POI_ID FOREIGN KEY (POI_ID) REFERENCES POI (ID) ALTER TABLE POI_ADDITIONAL ADD CONSTRAINT FK_POI

Navigation method/s in criteria fetch joins in JPA 2.1

江枫思渺然 提交于 2021-01-27 17:10:48
问题 While using fetch joins in JPA criteria, there is no navigation method can be seen. Given below an example. Root<UserTable> root = criteriaQuery.from(entityManager.getMetamodel().entity(UserTable.class)); Fetch<UserTable, StateTable> fetch = root.fetch(UserTable_.stateTable, JoinType.INNER); To navigate through the entity in question, this Fetch type is required to be cast to a join like as follows. Join<UserTable, StateTable> join = (Join<UserTable, StateTable>) root.fetch(UserTable_

@Transactional in the controller

落爺英雄遲暮 提交于 2021-01-27 17:09:31
问题 First of all I want to mention that I fully agree to only make the service layer transactional, but sometimes world is not perfect, and right now I´m in the middle of that situation. Basically I have been assigned into a wonderful project with a legacy code of 4+ years. The thing is that the developers did not follow any pattern where to introduce the bussines logic so you can image multiples services call from the controller and after that some extra call to private method into the

How to mock @PrePersist method?

故事扮演 提交于 2021-01-27 11:50:23
问题 How do I mock a @PrePersist method, e.g. preInit(), of an entity that I instantiate? I'm using TestNG. EasyMock is prefered. @Test(enabled = true) public void testCreateOrder() { // Instantiating the new mini order will automatically invoke the pre-persist method, which needs to be mocked/overwritten! MiniOrder order = new MiniOrder(); order.setDate(new Date()); order.setCustomerId(32423423); } The MiniOrder.java is an entity that has a pre-persist method. Again, the one I like to mock

Spring Data (JPA) multiple repositories without many classes

ぃ、小莉子 提交于 2021-01-27 10:29:25
问题 In my current project I'm using Spring Data JPA and I have more than 20 @Entity classes. I want to create repositories for them, but creating another classes, each for any model, with @Repository annotation seems to be some kind of overkill and a lot of "repeated" code - all repository classes will look like: @Repository public interface SomeModelRepository extends CrudRepository<SomeModel, Long> { } There is any way to create "automagically" those repositories? And specify only those that I

JPA - createEntityManagerFactory returns Null

只谈情不闲聊 提交于 2021-01-27 07:56:59
问题 Noob question here. I'm following this example/tutorial to try and isolate a problem I keep getting on my main project. Problem is, the entityManagerFactory keeps returning null (thus, I get a NullPointerExcept when trying to run the first JUnit test.) I'm currently on Eclipse Indigo (JavaEE) - JRE7 - Hibernate 3.6.7 and JBoss 7 And here's my persistence.xml (again, a copipasta taken right from the tutorial) <persistence> <persistence-unit name="examplePersistenceUnit" transaction-type=