jpa

javax.persistence.RollbackException: Transaction marked as rollbackOnly

廉价感情. 提交于 2021-01-28 05:47:09
问题 I'm making a game with Spring MVC. I have a method for get the game and update but when it goes to update it gives an error, this is the code: HomeController.class @Transactional @RequestMapping(value = "/partida/{idPartida}", method = RequestMethod.GET) public String getPartida(@PathVariable("idPartida") long idPartida, Model model) throws IOException { Partida p = ServicioAplicacionPartida.getPartida(entityManager, idPartida); if (p.getJson() == null) { p.inicializarPartida(entityManager);

JPA @OnetoOne self reference relationship with both columns non null

耗尽温柔 提交于 2021-01-28 05:28:16
问题 I have an existing database table For e.g. T_STUDENTS on top of which I have to create a JPA entity. All three columns in the table are NON NULL and the table has a self-reference as mentor_id id | name | mentor_id -----|---------|---------- 1 | John | 1 -----|---------|---------- 2 | Marc | 1 -----|---------|---------- 3 | Abby | 2 -----|---------|---------- 4 | Jimy | 3 -----|---------|---------- 5 | Boni | 4 -----|---------|---------- Each student has a mentor who is also a student. There

QuerySyntaxException with enum

时光总嘲笑我的痴心妄想 提交于 2021-01-28 05:25:32
问题 I have a UserAssignmentRole class like this : @Data @Entity public class UserAssignmentRole { ... @Enumerated(EnumType.STRING) public Role role; } And the Role is enum, it looks like this: public enum Role{ admin, member, pending } Now when in my repository I try to query to select all with role of admin, it gives me error: @Query("select uar from UserAssignmentRole uar where uar.role=Role.admin") public List<UserAssignmentRole> listAdmin(Long userID, Long assignmentID); How this can be

Subqueries in select in eclipselink

放肆的年华 提交于 2021-01-28 04:38:47
问题 According to EclipseLink documentation it supports subqueries in the select clause (even if JPA doesn't require it). When I try to use this feature in JPA Criteria API: myCriteriaQuery .multiselect(Arrays.asList(mySubquery, ...)) .where(...) there is an error: java.lang.ClassCastException: org.eclipse.persistence.internal.jpa.querydef.SubQueryImpl cannot be cast to org.eclipse.persistence.internal.jpa.querydef.SelectionImpl at org.eclipse.persistence.internal.jpa.querydef.CriteriaQueryImpl

Spring MVC OptionalValidatorFactoryBean not found

眉间皱痕 提交于 2021-01-28 03:56:00
问题 Hi I have set up a Spring MVC (4)+Postgresql+JPA app and I encountered the following situation: I want to set up custom queries for my "User" repository so added these lines to the existing (empty) UserRepository: public interface AccountRepository extends JpaRepository<User,Long> { @Query("select u from User u where u.Email = ?1") User findByEmail(String emailAddress); } With the empty Repository, everything is OK with the server, with the verison above I got the following exception on

Unidirectional @OnetoMany mapping deletes all relationships and re-adds remaining ones rather than removing the specific one

╄→尐↘猪︶ㄣ 提交于 2021-01-28 01:56:22
问题 Given the following code public class Course { @Id @GeneratedValue private Long id; private String name; @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) private List<Review> reviews = new ArrayList<>(); } public class Review { @Id @GeneratedValue private Long id; @Column(nullable = false) private String rating; private String description; } Saved course with 2 reviews. If I try to remove one review from course. course.getReviews().remove(0); Hibernate fires following queries.

Cascading a Child entity persist operation to its Parent entity

南笙酒味 提交于 2021-01-28 00:30:23
问题 I have a OneToMany association with two entities that I have set up using Hibernate annotations. The Child entity of this association has a composite primary key that consists of the foreign key parent column and another identifier childName . This seems to cause a "Referential integrity constraint violation" when I attempt to cascade a commit to the parent by saving the child entity. I have created a simple working example of the issue that abstracts away from the actual scenario that I am

How to override @SequenceGenerator(name = “idGenerator”, sequenceName = “HIBERNATE_SEQUENCE”, allocationSize = 50)

[亡魂溺海] 提交于 2021-01-27 23:56:03
问题 Normally Id column is as follows and it works perfectly fine and generated sequence values @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "idGenerator") @SequenceGenerator(name = "idGenerator", sequenceName = "HIBERNATE_SEQUENCE", allocationSize = 50) @Column(name = "ID") public Long getId() { return mId; } Now what I want is if in program I set xyz.setId(200) it should save Id as 200 instead of one generated by sequence.Now how can I acheive this? I also want to use both

Does java spring boot provides query builder like php CodeIgniter query builder

做~自己de王妃 提交于 2021-01-27 23:08:56
问题 We are developing an application in spring boot, where we will be creating and publishing dynamic forms into our application at runtime to post the form-data into the db (MySql) in JSON format. We want to create a generic api to handle CRUD operations for all dynamic forms. We know about the php code-igniter framework query builder, which is capable to build and execute the queries. https://www.codeigniter.com/userguide3/database/query_builder.html#inserting-data For example : $query = $this-

Does @PreUpdate always run when @PrePersist runs?

梦想的初衷 提交于 2021-01-27 20:23:16
问题 I have an Entity like below: @Entity public class Order { @Id private String orderId; @Temporal(TemporalType.TIMESTAMP) @Column(name = "created_at", nullable = false) private Date created; @Temporal(TemporalType.TIMESTAMP) @Column(name = "updated_at", nullable = false) private Date updated; @PrePersist protected void onCreate() { this.created = new Date(); this.updated = this.created; } @PreUpdate protected void onUpdate() { this.updated = new Date(); } } I have to find all the orders that