jpa

Hibernate Unable to load class []

人走茶凉 提交于 2021-01-29 21:37:37
问题 I recently added a few features (connecting database tables to other tables) using JPA (with hibernate). It worked fine before, but now I'm getting the exception org.hibernate.boot.registry.classloading.spi.ClassLoadingException: Unable to load class [] - or at least I think that's the most relevant part of it. The whole exception is: org.apache.tapestry5.ioc.internal.OperationException: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc

Will hibernate increment version if I add/remove/update element of dependable collection?

人走茶凉 提交于 2021-01-29 21:28:14
问题 I am learning hibernate optimistic lock mechanism and I haven't found answer on my question in user guide Let's say we have entity like this: @Entity class Employee{ @Version Long versionField; List<Employee> subordinates; ... } And somewhere we have following code: Employee sub = .... Emplyee emp = readEmploye(); emp.getSubordinates().add(sub); Can I control of version incrementation at this case ? 回答1: By default no. Since you're not changing the entity, but rather other entities that are

JPA filtering entities from a mapped association

安稳与你 提交于 2021-01-29 21:22:03
问题 My friendships sql table has column friend_1, friend_2, status . I have the following mappings in my (snippet below) User class. Currently user.getInitiatedFriendships returns list of Friendships where value of column friend_1 is equal to ID of the user I'm calling this getter on. user.getInvitedToFriendships() returns Friendships where column friend_2 is equal to ID of this user. I want to know if it is possible to add something to this line @OneToMany(mappedBy = "invitingUser" +>some check

JPA filtering entities from a mapped association

 ̄綄美尐妖づ 提交于 2021-01-29 19:06:06
问题 My friendships sql table has column friend_1, friend_2, status . I have the following mappings in my (snippet below) User class. Currently user.getInitiatedFriendships returns list of Friendships where value of column friend_1 is equal to ID of the user I'm calling this getter on. user.getInvitedToFriendships() returns Friendships where column friend_2 is equal to ID of this user. I want to know if it is possible to add something to this line @OneToMany(mappedBy = "invitingUser" +>some check

Spring Boot JPA CrudRepository - entities are not attached to persistencecontext

ε祈祈猫儿з 提交于 2021-01-29 16:47:01
问题 I'm currently implementing my first spring boot application after years of JEE. I am wondering about JPA / Hibernate behaviour. In JEE, once persisted or "find" an @Entity, all changes to this Entity are populated automatically by the JPA implementation to the database without any need to call persist(), flush() etc. Now with a CrudRepository changes are only stored to the database if I explicitely call save(). My CrudRepository: public interface UserAccountRepository extends CrudRepository

Mapping controller endpoints to Spring JPA layer

杀马特。学长 韩版系。学妹 提交于 2021-01-29 16:12:32
问题 I've written this request mapping to access a ticket by it's id with the optional request parameters ticketType & ticketStatus : @GetMapping(path = "/tickets/{ticketId}") @ResponseStatus(value = HttpStatus.OK) public ResponseEntity<List<TicketResponse>> getTicketsById(@PathVariable("ticketId") final Long ticketId, @RequestParam("ticketType") final String ticketType, @RequestParam("ticketStatus") final String ticketStatus) Currently the repository contains methods for returning based on either

Using the same predicates for two criteria queries

孤人 提交于 2021-01-29 14:52:39
问题 I want to run a pair of queries using the same array of Predicate : one to count the records, one to get a certain page of records. This seems like a pretty normal use case, to me, so there must be a good way to do it, but I have yet to find it. So this is the part that fetches entities: CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); EntityType<ENTITY> entityType = entityManager.getMetamodel().entity(FooEntity.class); CriteriaQuery<FooEntity> entityQuery =

Spring Boot : Using JPA want to get the unique value from table

喜欢而已 提交于 2021-01-29 13:29:09
问题 I have a table CatID | CategoryName | scatID | subCategoryName 2 User 1 x 2 User 2 y 2 User 3 z 2 User 4 a 2 User 5 b I am able to get all the value in JSON formate using SpringBoot. My Requirement : I want to get the unique CategoryName attribute but in current scenario I am getting all User coming 5 times. I am looking for solution. Please any one can help to get over using Spring Boot JPA implementation. 回答1: You can use the Query annotation in your repository interface. For example, below

Retrieve primary key from entity class from sessionfactory in hibernate

元气小坏坏 提交于 2021-01-29 13:21:32
问题 I am creating one SessionFactory using hibernate and I need the primary key of all the tables associated with the entity classes generated from the SessionFactory. Is there any way to achieve this? I have created SessionFactory and from the gathered the ClassMetaData. But unable to retrieve the primary key from the ClassMetaData. 回答1: I don't know which Hibernate version you have. This works for version 4.2.x: Configuration con = // get the org.hibernate.cfg.Configuration for(Iterator

Circular Dependency bidirectional @OneToMany JPA relationship

别说谁变了你拦得住时间么 提交于 2021-01-29 12:39:10
问题 Given the following two entities: @Entity public class Goal { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String description; private BigDecimal amount; @Email private String email; @Email private String supervisorEmail; private LocalDateTime deadline; @Enumerated(EnumType.STRING) @Column(nullable = false) private PaymentPurpose purpose; @Enumerated(EnumType.STRING) private GoalStatus status; @ManyToOne(cascade = CascadeType.ALL) private Person person; /