hibernate

repeatable read and second lost updates issue

早过忘川 提交于 2021-02-18 14:59:11
问题 With repeatable read isolation level, it is still possible to lose updates (second lost updates problem). E.g. in the scenario with isolation level set to RR: 1) transaction t1 reads data from row r1, 2) transaction t2 reads same data from row r1, 3) t1 modifies the data read in #1 and commits data to r1 4) t2 modifies the data read in #2 and commits data to r1. t1's update is lost I tried this with Hibernate (isolation level set to RR) and saw the behavior as mentioned above. Why then is it

JPA Native query get a Single Object

佐手、 提交于 2021-02-18 12:17:06
问题 How can i get a single object by using JPA Native query. I did some researches but all give an answer is use "getSingleResult", however it didn't return what i want to get. For example, what should i do if i want to get a count of table in my database and fetch it into a Integer. This code below shows how i get this by using Sessison hibernate: int check = Integer.parseInt((String) sessionF.createSQLQuery("select to_char(count(*)) as count from user_tables where table_name upper('TEST')")

session/entitymanager is closed

蹲街弑〆低调 提交于 2021-02-18 12:17:01
问题 i have this hibernate dao and it works fine while testing in my local machine. but for some transaction it throws IllegalStateException. i believe it is because multiple users hitting at same time.(i may be wrong). UpdatePaymentDao @Repository public class UpdatePaymentImpl implements UpdatePayment { @Autowired SessionFactory sessionFactory; Session session; Transaction trans; private static final long LIMIT = 100000000000L; private static final long LIMIT2 = 10000000000L; private static long

EJB/JPA Transaction Boundaries

情到浓时终转凉″ 提交于 2021-02-18 11:17:10
问题 I was reading EJB Transaction boundary and Transaction boundary Lets concentrate on RequiresNew Attribute . Here is the modified diagram from the link So let say method-B is annotated with RequiredNew attribute . so according to theory when method-A calls method-B a new transaction will be start and the already started transaction will be suspended, and when method-B returns the new transaction will be committed. Now consider that in section S1 we create a jpa entity using entitymanager

Generic enum JPA AttributeConverter implementation

╄→гoц情女王★ 提交于 2021-02-18 07:39:28
问题 Problem I am trying to solve I am trying to implement enum mapping for Hibernate. So far I have researched available options, and both the @Enumerated(EnumType.ORDINAL) and @Enumerated(EnumType.STRING) seemed inadequate for my needs. The @Enumerated(EnumType.ORDINAL) seems to be very error-prone, as a mere reordering of enum constants can mess the mapping up, and the @Enumerated(EnumType.STRING) does not suffice too, as the database I work with is already full of values to be mapped, and

Merge an entity, change its id, merge again, cause “mapped to a primary key column in the database. Updates are not allowed” error

百般思念 提交于 2021-02-18 05:20:44
问题 I have a JPA program where EclipseLink is the Persistence provider. When I merge an user entity, change its ID, and try to merge the same user instance again, an error is thrown. I rewrite my code to illustrate my problem in the simplest way. User user = userManager.find(1); userManager.merge(user); System.out.println("User is managed? "+userManager.contains(user); user.setId(2); userManager.merge(user); The above code is not in a transaction context. userManager is a stateless session bean

How do you retrieve nested Sets?

瘦欲@ 提交于 2021-02-17 22:08:56
问题 Is there an annotation I'm missing or is this a limitation to hibernate retrieval? Entities: class A { Long id; Set<B> b; @ManyToMany(fetch = FetchType.EAGER) @JoinTable(name = "A_B", joinColumns = @JoinColumn(name = "A_ID"), inverseJoinColumns = @JoinColumn(name = "B_ID") public Set<B> getBs() { return b; } } class B { Long id; Set<C> c; @ManyToMany(fetch = FetchType.EAGER) @JoinTable(name = "B_C", joinColumns = @JoinColumn(name = "B_ID"), inverseJoinColumns = @JoinColumn(name = "C_ID")

How do you retrieve nested Sets?

蓝咒 提交于 2021-02-17 22:08:08
问题 Is there an annotation I'm missing or is this a limitation to hibernate retrieval? Entities: class A { Long id; Set<B> b; @ManyToMany(fetch = FetchType.EAGER) @JoinTable(name = "A_B", joinColumns = @JoinColumn(name = "A_ID"), inverseJoinColumns = @JoinColumn(name = "B_ID") public Set<B> getBs() { return b; } } class B { Long id; Set<C> c; @ManyToMany(fetch = FetchType.EAGER) @JoinTable(name = "B_C", joinColumns = @JoinColumn(name = "B_ID"), inverseJoinColumns = @JoinColumn(name = "C_ID")

Explanation of the second level cache code in Hibernate?

那年仲夏 提交于 2021-02-17 05:49:12
问题 I have the two following entities @Cachable class Book{ ... @ManyToOne Publisher publisher; } @Cachable{ class Publisher{ ... } I have the following test code, @Test public void test{ stats = sessionFactory.getStatstics(); ... Book book = session.byId(Book.class).load(1); Book book2 = session.byId(Book.class).load(1); assertEquals(stats.getSecondLevelCacheHitCount,0); assertEquals(stats.getSecondLevelCacheMissCount,1); assertEquals(stats.getSecondLevelCachePutCount,2); } Why the cache miss

JPA Entity class giving error with 2 @GeneratedValue fields

霸气de小男生 提交于 2021-02-17 05:11:12
问题 I have two columns which will use @GeneratedValues, but when I am putting them like this it is giving error; " Exception Description: Class [class Testing] has two @GeneratedValues: for fields [Testing.SEQ_NO] and [Testing.ID]. Only one is allowed. " @Table(name = "TABLE1") @Entity public class Testing{ @GeneratedValue(strategy=GenerationType.AUTO) @Id private Long id; @Column(name = "LINKAGE_ID") private int linkageId; @Column(name = "TRANSFER_ID") private int transferId; @Column(name =