You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Jérôme <th...@hotmail.com> on 2013/01/23 14:52:47 UTC

Insert not using foreign key

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.

Re: Insert not using foreign key

Posted by Jérôme <th...@hotmail.com>.
DATA_QUERY_REF is in the FctData table it's the foreign key to the id of
DataQuery.
So it's not a date.



--
View this message in context: http://openjpa.208410.n2.nabble.com/Insert-not-using-foreign-key-tp7582616p7582618.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Insert not using foreign key

Posted by José Luis Cetina <ma...@gmail.com>.
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" <th...@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.
>