English 中文(简体)
在视图中重复主键的重复行
原标题:duplicated rows which have duplicated primary key in a view
  • 时间:2012-05-23 16:09:22
  •  标签:
  • hibernate

i 显示 i 视图 (2 个表格 ans 1 关联), 并像这样映射

@Id
@Column(name = "IDBQ", precision = 5, scale = 0)
public Integer getIdbq() {
    return this.idbq;
}

public void setIdbq(Integer idbq) {
    this.idbq = idbq;
}


@Column(name = "IDR", precision = 22, scale = 0)
public Integer getIdr() {
    return this.idr;
}

public void setIdr(Integer idr) {
    this.idr = idr;
}

@Column(name = "NOM_CLIENT",  length = 100)
public String getNomClient() {
    return this.nomClient;
}

public void setNomClient(String nomClient) {
    this.nomClient = nomClient;
}

@Column(name = "PRENOM_CLIENT",  length = 30)
public String getPrenomClient() {
    return this.prenomClient;
}

and beacause it s a view the primary key IDBQ in many rows is duplicated. the probleme when i make a request hql from hibernate it return : duplicated rows which have duplicated Id -> IDBQ

如果我有:

IDBQ -- IDR -- NOM_CLIENT -- PRENOM_CLIENT
1       1     xx            xxx
1       2     yy            yyy

照我的要求还我

1       1     xx            xxx
1       1     xx            xxx

但Sql要求工作鳍!

问题回答

如果在您看来有多个行的同一身份标识,那么这意味着您的身份标识不是一个身份标识。根据您所张贴的信息, < code> [IDBQ, IDR] 应该是该实体的身份标识。

您之所以看到重复行的原因是因为您有两张带有相同主密钥的记录( 在您的例子中为 IDBQ ) 。 在从数据库检索数据时, 同一标识符的记录会引用同一对象( 取决于顺序)。 这叫做 身份地图 Patter 。 < a href=" https:// en.wikipedia. org/ wiki/ Identity_ map_ pattern" rel= “ nofollown noreferrerr” > 跟随此链接获取更多信息 。

Even though your view has 2 different rows with same identifier on your query editor, Your Entity Framework produces incorrect output. When the 1st row with IDBQ value 1 is loaded from the database it is retrieved as expected but when the 2nd row with same IDBQ value 1 is retrieved, the same object is returned (1 | 1 | xx | xxx) since there is an object with PK 1 already loaded. Hope you find this helpful.





相关问题
Multiple Hibernate instances using C3P0

I am facing a weird problem and it seems to be c3p0 related. I am starting two instances of an app in the same java vm which interact with each other. After some operations "APPARENT DEADLOCK" ...

Hibernate vs Ibatis caching

We can speed up a hibernate app easyly with 2nd level cache using infinispan or ehcache/terracotta,... but ibatis only have a simple interface to implement for caching. And hibernate knows more ...

Using annotations to implement a static join in hibernate

I m relatively new to hibernate and was wondering if someone could help me out. While I have no issues implementing a normal join on multiple columns in hibernate using the @JoinColumns tag, I m ...

Hibernate query with fetch question

I have a 2 entities in a One-To-Many relationship: OfficeView.java: public class OfficeView implements java.io.Serializable { private Integer officeId; private String addr1; private ...

hibernate interceptors : afterTransactionCompletion

I wrote a Hibernate interceptor : public class MyInterceptor extends EmptyInterceptor { private boolean isCanal=false; public boolean onSave(Object entity, Serializable arg1, Object[] arg2, String[]...

How to prevent JPA from rolling back transaction?

Methods invoked: 1. Struts Action 2. Service class method (annotated by @Transactional) 3. Xfire webservice call Everything including struts (DelegatingActionProxy) and transactions is configured ...

Hibernate/GORM: collection was not processed by flush()

I have an integration test in my Grails application that fails when I try to save an entity of type Member invitingMember.save(flush: true) This raises the following exception org.hibernate....

Hibernate Criteria API equivalent for "elements()"

Is it possible to implement the following query using Criteria API? select order from ORDER as order,ITEM as item where item.itemID like ITM_01 and item in elements(order.items)

热门标签