openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From José Luis Cetina <maxtorz...@gmail.com>
Subject Re: Insert not using foreign key
Date Wed, 23 Jan 2013 14:11:37 GMT
Check your table where the field DATA_QUERY_REF is. This field have a
"wrong" date value. Some date before 1970 or just like 0000-00-00 could be
the problem. JPA sometimes do selects before inserts.
El 23/01/2013 07:53, "Jérôme" <the_supergg@hotmail.com> escribió:

> Hi guys,
>
> I'm trying to create a little project around EJB / JPA linked to a Mysql
> database. I got two tables FctData and RefKpiDataQuery linked by a foreign
> key.
>
> FctData :
>
> public class FctData implements Serializable {
>
>     @Id
>     @GeneratedValue(strategy = GenerationType.IDENTITY)
>     @Column(name = "DATA_ID")
>     private Long dataId;
>
>     ...
>
>     @JoinColumn(name = "DATA_QUERY_REF", referencedColumnName =
> "KPI_DATA_QUERY_ID")
>     @ManyToOne(cascade = CascadeType.ALL)
>     private RefKpiDataQuery dataQueryRef;
>
> ----------------
>
> RefKpiDataQuery :
>
> public class RefKpiDataQuery implements Serializable {
>
>     @Id
>     @GeneratedValue(strategy = GenerationType.IDENTITY)
>     @Basic(optional = false)
>     @Column(name = "KPI_DATA_QUERY_ID")
>     private Long kpiDataQueryId;
>
>     ...
>
>     @OneToMany(cascade = CascadeType.ALL, mappedBy = "dataQueryRef")
>     private Set<FctData> fctDataSet;
>
> I got a client which is just trying to insert a FctData in the database
>
> RefKpiDataQuery refKpiDataQuery = new RefKpiDataQuery();
> refKpiDataQuery.setKpiDataQueryId((long) 2);
>
> FctData fctData = new FctData();
> fctData.setDataQueryRef(refKpiDataQuery);
>
> fctDataFacade.insert(fctData);
>
>
> The Facade is a kind of DAO. This thing is working great with object which
> don't have a FK.
>
> Here is the error that i get in my log :
>
> Field 'DATA_QUERY_REF' doesn't have a default value {prepstmnt 7235700
> INSERT INTO FCT_DATA(DATA_DATE, DATA_TIME, DATA_VALIDITY, DATA_VALUE,
> ISACTIVE, UPDATE_OWNER, UPDATE_TS) VALUES (?, ?, ?, ?, ?, ?, ?)
>
>
> As we can see in my insert it never talks about the dataQuery. Someone can
> explain me what did i miss ? I can't find my mistake.
>
> Thanks for your time. Cheers
>
>
>
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/Insert-not-using-foreign-key-tp7582616.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message