Quantcast

One-to-one not working after upgrade from 1.1.1 to 2.1.0

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

One-to-one not working after upgrade from 1.1.1 to 2.1.0

pgraham
Hi All,

I am experience issues after upgrade an app from Grails 1.1.1 to 2.1.0 with a one-to-one relationship in a hibernate model.  The models involved in the relationship are defined as follows:

app-root
    -> src
        -> java
            Dashboard.java
            DashboardFilter.java

Dashboard.java:

@Entity
@Table(name="dashboard")
class Dashboard {

    // ...

    private DashboardFilter filter;

    // ...

    @OneToOne
    public DashboardFilter getFilter() {
        return filter;
    }
    public void setFilter(DashboardFilter filter) {
        this.filter = filter;
    }

    // ...
}

DashboardFilter.java:

@Entity
@Table(name="dashboard_filter")
public class DashboardFilter {

    private long id;

    // ...

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name="id")
    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    // ...
}

The problem is that when Dashboard.list() is invoked, the following SQL is generated:

select this_.id as id36_1_,
       -- ...
       this_.filter as filter36_1_,
       dashboardf2_.id as id37_0_,
       -- ...
from dashboard this_
left outer join dashboard_filter dashboardf2_ on this_.filter=dashboardf2_.id

This results an error because the name of the column is filter_id and per the hibernate docs this is what should be generated as the default join column for a one-to-one relationship.

The proper column name is generated when using Grails 1.1.1.

My datasource is configuration as follows:

dataSource {
            configClass = GrailsAnnotationConfiguration.class
            dialect = org.hibernate.dialect.Oracle10gDialect
            driverClassName = "oracle.jdbc.driver.OracleDriver"
            url = "jdbc:oracle:thin:@XXXXXX:1521:XXXXXX"
            username = "XXXXXX"
            password = "XXXXXX"
            logSql = true
        }

Does anyone have any idea if this is expected behaviour due to a change in either GORM or Hibernate or if it is a bug?

Thanks,
Philip
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: One-to-one not working after upgrade from 1.1.1 to 2.1.0

Graeme Rocher-4
Administrator
This is more of a hibernate question since you're using Hibernate
mappings, there is probably a difference between Hibernate 3.3 and 3.6

Cheers

On Fri, Jul 27, 2012 at 7:56 PM, pgraham <[hidden email]> wrote:

> Hi All,
>
> I am experience issues after upgrade an app from Grails 1.1.1 to 2.1.0 with
> a one-to-one relationship in a hibernate model.  The models involved in the
> relationship are defined as follows:
>
> app-root
>     -> src
>         -> java
>             Dashboard.java
>             DashboardFilter.java
>
> Dashboard.java:
>
> @Entity
> @Table(name="dashboard")
> class Dashboard {
>
>     // ...
>
>     private DashboardFilter filter;
>
>     // ...
>
>     @OneToOne
>     public DashboardFilter getFilter() {
>         return filter;
>     }
>     public void setFilter(DashboardFilter filter) {
>         this.filter = filter;
>     }
>
>     // ...
> }
>
> DashboardFilter.java:
>
> @Entity
> @Table(name="dashboard_filter")
> public class DashboardFilter {
>
>     private long id;
>
>     // ...
>
>     @Id
>     @GeneratedValue(strategy=GenerationType.AUTO)
>     @Column(name="id")
>     public long getId() {
>         return id;
>     }
>
>     public void setId(long id) {
>         this.id = id;
>     }
>
>     // ...
> }
>
> The problem is that when Dashboard.list() is invoked, the following SQL is
> generated:
>
> select this_.id as id36_1_,
>        -- ...
>        this_.filter as filter36_1_,
>        dashboardf2_.id as id37_0_,
>        -- ...
> from dashboard this_
> left outer join dashboard_filter dashboardf2_ on
> this_.filter=dashboardf2_.id
>
> This results an error because the name of the column is filter_id and per
> the hibernate docs this is what should be generated as the default join
> column for a one-to-one relationship.
>
> The proper column name is generated when using Grails 1.1.1.
>
> My datasource is configuration as follows:
>
> dataSource {
>             configClass = GrailsAnnotationConfiguration.class
>             dialect = org.hibernate.dialect.Oracle10gDialect
>             driverClassName = "oracle.jdbc.driver.OracleDriver"
>             url = "jdbc:oracle:thin:@XXXXXX:1521:XXXXXX"
>             username = "XXXXXX"
>             password = "XXXXXX"
>             logSql = true
>         }
>
> Does anyone have any idea if this is expected behaviour due to a change in
> either GORM or Hibernate or if it is a bug?
>
> Thanks,
> Philip
>
>
>
> --
> View this message in context: http://grails.1312388.n4.nabble.com/One-to-one-not-working-after-upgrade-from-1-1-1-to-2-1-0-tp4632345.html
> Sent from the Grails - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>



--
Graeme Rocher
Grails Project Lead
SpringSource - A Division of VMware
http://www.springsource.com

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Loading...