jpa

Extra columns in many-to-many Spring Data JPA Relationship with minimal changes

こ雲淡風輕ζ 提交于 2021-01-28 11:53:05
问题 I need to make a change in the project's model. Nowadays we have two classes with bidirectional many-to-many relationship (which implies in an relationship table) and need now to add extra informations to the relationship. My question is: The only way to do it is create a class for the relationship (e.g. creating this one with the same name of the relationship table that already exists)? I'm asking it because if we need to change the above relationship in the project, the change will be very

Hibernate optimistic locking different behavior between Postgres and MariaDb

两盒软妹~` 提交于 2021-01-28 11:21:29
问题 I just discovered that my application behaves differently when I use optimistic locking with a Postgresql or a MariaDB database and I am wondering if somebody can explain what happens and how could I make the application work in the same way with MariaDB? I use Postgresl 10.5 and MariaDB 10.3.10 with InnoDB engine and default settings. I use Spring framework version 5.1.0 and Hibernate 5.3.6. So my code looks like this: @Entity @Getter @Setter @NoArgsConstructor public class Bla { @Id

SQL Error: 1064, SQLState: 42000 in @Query - JPA, MySQL, Hibernate

半腔热情 提交于 2021-01-28 08:13:24
问题 I am using JPA Query for MySQL database. I am passing String date in http://localhost:8081/stat/visits/2020-07-29 as PathVariable - but getting an error in JPA Repository in Query: I am using Java8 LocalDateTime and for parameter LocalDate . Something is wrong with binding. Here are my classes and bellow the error: Controller @GetMapping("/visits/{dateParam}") public ResponseEntity<List<WebsiteDailyTotal>> getDailyTotalUsage(@PathVariable("dateParam") String dateParam) { LocalDate ld =

Is it possible to add functionality to the @Column annotation?

为君一笑 提交于 2021-01-28 07:57:37
问题 I'm wondering whether it is possible to add additional functionality to the @Column annotation in JPA. Specifically, what I would like to do is tag columns of sensitive data with an @ProtectedColumn annotation: this would then tell the persistence framework to apply some type of data protection (encryption, tokenization, whatever...) to the values when storing them into the actual data store, and then reverse that process when reading the values from the data store. So I might have a Customer

hbm2ddl - How to avoid that Hibernate is creating Foreign Key constraints?

若如初见. 提交于 2021-01-28 07:44:03
问题 Dear all I am using Hibernate with hbm2ddl. I don't like that for one relationship foreign key constraints get created. Unfortunately I could not achieve it so far. I tried it with Hibernate and JPA annotations, had no luck. Any hints? I am using Hibernate 4.3.1 and mysql 5.6 @Entity class Artikel { ... @OneToMany(fetch=FetchType.LAZY, mappedBy="artikel") @NotFound(action=NotFoundAction.IGNORE) private List<Bild> images; } import javax.persistence.Entity; import javax.persistence.FetchType;

Springboot custom Select Query returns No converter found capable of converting from type

我只是一个虾纸丫 提交于 2021-01-28 06:54:14
问题 I am trying to execute a custom select query in Springboot JPA, public interface idnOauth2AccessTokenRepository extends JpaRepository<idnOauth2AccessToken, String>, JpaSpecificationExecutor<idnOauth2AccessToken> { @Query(value = "select IOCA.userName, IOCA.appName, IOAT.refreshToken, IOAT.timeCreated, IOAT.tokenScopeHash, IOAT.tokenState, IOAT.validityPeriod from idnOauth2AccessToken IOAT inner join idnOauthConsumerApps IOCA on IOCA.ID = IOAT.consumerKeyID where IOAT.tokenState='ACTIVE'")

How to perform a join fetch in JPA Criteria without unchecked casting?

邮差的信 提交于 2021-01-28 06:30:15
问题 I need to do a JOIN FETCH in JPA Criteria using a static metamodel, however I'm at a loss on how to do it without getting an unchecked exception warning. Suppose we have a Thing entity with a lazily-initialized Other entity inside it. I want to retrieve Things with fetched Others, where other.someField="someValue". This is roughly how I would do it: public List<Thing> getThings() { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Thing> cq = cb.createQuery(Thing.class); Root root =

Deserializing from JSON using foreign key

徘徊边缘 提交于 2021-01-28 06:07:49
问题 I have a many to one relationship: A *<-->1 B and I want to deserialize A from a JSON having B 's primary key ( B exists in db with that primary key): { "b": 1 } I have tried the following: @Entity @Table(name = "table_a") @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id") public class A implements Serializable { @JsonIgnore @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name = "b", unique = true, nullable = false) private B b; } and @Entity @Table(name =

Deserializing from JSON using foreign key

我怕爱的太早我们不能终老 提交于 2021-01-28 06:00:49
问题 I have a many to one relationship: A *<-->1 B and I want to deserialize A from a JSON having B 's primary key ( B exists in db with that primary key): { "b": 1 } I have tried the following: @Entity @Table(name = "table_a") @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id") public class A implements Serializable { @JsonIgnore @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name = "b", unique = true, nullable = false) private B b; } and @Entity @Table(name =

Problem with @OneToMany relations in a Generic CRUD

北战南征 提交于 2021-01-28 05:54:54
问题 I have this generic CRUD (Controller, Repository, Service, Specification) with multiple entities that use @OneToMany annotations. The project only starts when I comment on these annotations, otherwise I get an error that always indicates a different "DAO" file. Struchture: oga-servicio-principal -src/main/java --com.oga.springboot ---app.principal ----controllers ----crud (My Generic CRUD files) -----controllers -----models ------dao ------dto ------entity ------service ------specifications -