You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Rajeev Chaudhary (JIRA)" <ji...@apache.org> on 2010/05/17 20:00:56 UTC

[jira] Commented: (OPENJPA-1617) Why multiple SQL hit to database. for one to one mapping.

    [ https://issues.apache.org/jira/browse/OPENJPA-1617?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12868322#action_12868322 ] 

Rajeev Chaudhary commented on OPENJPA-1617:
-------------------------------------------

The solution here. I removed one-to-one mapping from PersonDto and have the following in FacPerson DTO class

@OneToOne(optional=false,cascade=CascadeType.ALL)
    @JoinColumn(name="PERS_ID",referencedColumnName="PERS_ID") 
	private PersonDto personDto; 

> Why multiple SQL hit to database. for one to one mapping.
> ---------------------------------------------------------
>
>                 Key: OPENJPA-1617
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-1617
>             Project: OpenJPA
>          Issue Type: Question
>          Components: jpa
>         Environment: Windows
>            Reporter: Rajeev Chaudhary
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> I have weblogic system libraries having javax.persistence_1.0.0.0_1-0.jar and org.apache.openjpa_2.2.0.0_1-1-0.jar.
> Entity Classes
> 1. @Entity @Table(name="E_FAC_PERS")
> public class FacPerson implements Serializable {
> 	private static final long serialVersionUID = 1L;
> 	@EmbeddedId
>            protected FacPersonPk facPK;
> 	@Column(name="FAC_ID")
> 	   private String facId;
> 	@Column(name="PERS_ID")
>             private String persId;
>        @OneToOne(mappedBy="facPerson",targetEntity=PersonDto.class,fetch=FetchType.EAGER)
> 	private PersonDto personDto; 
> }
> @Entity
> @Table(name="E_PERS")
> public class PersonDto extends BaseFacDto implements Serializable {
> 	private static final long serialVersionUID = 1L;
> 	@Id @Column(name="PERS_ID", nullable = false)
> 	private String perId;
>         @OneToOne(optional=false,cascade=CascadeType.ALL)
>         @JoinColumn(name="PERS_ID",referencedColumnName="PERS_ID") 
>         private FacPerson facPerson;
> }
> Question: I have defined two entity classes having one-to-one mapping. While running 
> List<FacPerson> results =  em2.createQuery("SELECT f FROM FacPerson f where f.facId='"+facId+"' order by f.position desc").getResultList();
> generates so many sql query shown in the Logs.  If I explicetly run the 1 query. I see the results I wanted. Why there are multiple hit to the database. Could you please help.
> SQL Logs..
> 1. SELECT t0.FAC_ID, t0.PERS_ID, t0.BEGIN_REC_DATE, -Removed some part of SQL-,, t0.START_DATE FROM E_FAC_PERS t0, E_PERS t1, E_PERS t2   WHERE (t0.FAC_ID = ? AND t0.PERS_ID = t1.PERS_ID) AND t0.PERS_ID = t2.PERS_ID(+) ORDER BY t0.POSITION DESC [params=(String) 0235]
> 2. SELECT t1.FAC_ID, t1.PERS_ID, t1.BEGIN_REC_DATE, -Removed some part of SQL-,t1.START_DATE FROM E_PERS t0, E_FAC_PERS t1, E_PERS t2 WHERE t0.PERS_ID = ? AND t0.PERS_ID = t1.PERS_ID AND t1.PERS_ID = t2.PERS_ID(+) [params=(String) MENEA1]
> 3. SELECT t1.FAC_ID, t1.PERS_ID, t1.BEGIN_REC_DATE, -Removed some part of SQL-, t1.START_DATE FROM E_PERS t0, E_FAC_PERS t1, E_PERS t2 WHERE t0.PERS_ID = ? AND t0.PERS_ID = t1.PERS_ID AND t1.PERS_ID = t2.PERS_ID(+) [params=(String) GALIJ1]

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.