You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Rajeev Chaudhary <ve...@gmail.com> on 2010/07/16 21:45:38 UTC

How can I prevent A child in one-to-one getting persisted/merge

How can I prevent A child in one-to-one getting persisted/merge. I only want
to fetch the child information. When I am persisting FacPersonDto, I get
error, saying the relation expects a value for the id. currently it is null.
I also tried making updatabale, insertable = false in
@JoinColumn(name="PERS_ID",referencedColumnName="PERS_ID") . But it didn't
work. Do I need any other setting to be done in the class. Please help. 

public class FacPersonDto extends BaseFacPersonDto implements Serializable {
	private static final long serialVersionUID = 1L;
	@EmbeddedId
         protected FacPersonPk facPK;
	@Column(name="NOTE")
	private String note;
	
       @OneToOne(optional=false,cascade=CascadeType.REFRESH)
       @JoinColumn(name="PERS_ID",referencedColumnName="PERS_ID") 
	private PersonDto personDto;

 .....

}

Note: I am using javax.persistence_1.0.0.0_1-0.jar ,
javax.transaction_1.0.0.0_1-1.jar.
-- 
View this message in context: http://openjpa.208410.n2.nabble.com/How-can-I-prevent-A-child-in-one-to-one-getting-persisted-merge-tp5303504p5303504.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: How can I prevent A child in one-to-one getting persisted/merge

Posted by Michael Dick <mi...@gmail.com>.
Hi,

You're getting an error because optional is set to false - try setting it to
true or removing it from the @OneToOne annotation.

-mike

On Fri, Jul 16, 2010 at 2:45 PM, Rajeev Chaudhary <ve...@gmail.com>wrote:

>
> How can I prevent A child in one-to-one getting persisted/merge. I only
> want
> to fetch the child information. When I am persisting FacPersonDto, I get
> error, saying the relation expects a value for the id. currently it is
> null.
> I also tried making updatabale, insertable = false in
> @JoinColumn(name="PERS_ID",referencedColumnName="PERS_ID") . But it didn't
> work. Do I need any other setting to be done in the class. Please help.
>
> public class FacPersonDto extends BaseFacPersonDto implements Serializable
> {
>        private static final long serialVersionUID = 1L;
>        @EmbeddedId
>         protected FacPersonPk facPK;
>        @Column(name="NOTE")
>        private String note;
>
>       @OneToOne(optional=false,cascade=CascadeType.REFRESH)
>       @JoinColumn(name="PERS_ID",referencedColumnName="PERS_ID")
>        private PersonDto personDto;
>
>  .....
>
> }
>
> Note: I am using javax.persistence_1.0.0.0_1-0.jar ,
> javax.transaction_1.0.0.0_1-1.jar.
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/How-can-I-prevent-A-child-in-one-to-one-getting-persisted-merge-tp5303504p5303504.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>