PostgreSQL Fluent NHibernate Map generated code

Posts   
 
    
cfcobio
User
Posts: 11
Joined: 06-Apr-2010
# Posted on: 09-Jun-2010 17:37:13   

Hi, I'm testing nhibernate framework with llblgen 3.0 and postgresql, the generated code in EntityMappings has the following errors,

In class constructor with the method "Table" the string parameter of table name is generated in this form ""schema01"."table01"" it should be "\"schema01\".\"table01\"" to compile.

Also when mapping the sequence in primary key field, the string is not correct

Id(x=>x.Id) .Access.CamelCaseField(Prefix.Underscore) .Column("id") .GeneratedBy.Native("schema01"."table01_id_seq");

cfcobio
User
Posts: 11
Joined: 06-Apr-2010
# Posted on: 09-Jun-2010 17:44:16   

Also the same error with typed view table name mapping.

public class View01TypedViewRowMap : ClassMap<View01TypedViewRow> { /// <summary>Initializes a new instance of the <see cref="View01ViewRowMap"/> class.</summary> public View01TypedViewRowMap() { Table(""schema01"."view01"");

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 09-Jun-2010 18:24:30   

Thanks cfcobio, looks like the generalutils template doesn't escape strings properly. We'll look into it and fix it a.s.a.p.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 10-Jun-2010 13:07:23   

Indeed a problem with string pattern production. We properly escape the string's quotes, but NOT if that string is to be used inside a string.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 10-Jun-2010 14:42:50   

Fixed in next build. It's only present in fluent nhibernate mappings btw.

Frans Bouma | Lead developer LLBLGen Pro
cfcobio
User
Posts: 11
Joined: 06-Apr-2010
# Posted on: 10-Jun-2010 18:25:05   

Ok, thanks. simple_smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 10-Jun-2010 18:25:53   

cfcobio wrote:

Ok, thanks. simple_smile

It's now available.

Frans Bouma | Lead developer LLBLGen Pro
cfcobio
User
Posts: 11
Joined: 06-Apr-2010
# Posted on: 10-Jun-2010 18:49:44   

Now it works, btw this framework is interesting.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 10-Jun-2010 20:57:01   

cfcobio wrote:

Now it works, btw this framework is interesting.

yes, it has its advantages simple_smile

Frans Bouma | Lead developer LLBLGen Pro
cfcobio
User
Posts: 11
Joined: 06-Apr-2010
# Posted on: 10-Jun-2010 22:08:04   

I have another error.

I have a table with a two field primary key (pk_p1, pk_p2 both fields are integer) and one field with unique not null foreign key, when I create with SessionManager.OpenSession, it throws an exception with this inner exception message:

Foreign key (FK235BB0F082CB31FB:"public"."table2" [id])) must have same number of columns as the referenced primary key ("public"."table3" [pk_p1, pk_p2])

My tables have the next fields

Table2 Field - Type id serial pk data01 integer not null data02 varchar(64) not null

Table3 Field - Type pk_p1 integer pk pk_p2 integer pk fk_t2 integer not null (Foreign key to table2-id)

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 10-Jun-2010 22:12:22   

Could you attach the .llblgenproj file or email it to us (support AT llblgen DOT com) ? thanks.

Frans Bouma | Lead developer LLBLGen Pro
cfcobio
User
Posts: 11
Joined: 06-Apr-2010
# Posted on: 10-Jun-2010 22:45:43   

I attached the files, also I tried to generate with XML mapping but it seems there is an error with parsing the xml when openning a session, it says an unexpected token its found, this token is public in line 6

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   assembly="NhfluentTest2.Model"
                   namespace="Testing2.EntityClasses">
                
    <class name="Table3" table=""public"."table3"" optimistic-lock="version" >
        <composite-id>
            <key-property name="PkP1" column="pk_p1" />
            <key-property name="PkP2" column="pk_p2" />
        </composite-id>
        <many-to-one name="Table2EntityViaFkT2" access="field.camelcase-underscore" fetch="select">
            <unique="true"/>
            <column name="fk_t2"/>
        </many-to-one>

    </class>
</hibernate-mapping>

I think it is the quote again. I changed the inner quotes with " and then another exception with line 12, <unique="true">. I don't know yet about nhibernate xml mapping.

simple_smile

Attachments
Filename File size Added on Approval
NHFluentTest.llblgenproj 13,834 10-Jun-2010 22:46.40 Approved
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 10-Jun-2010 23:19:08   

Thanks for the project, we'll look into it. We didn't have any probs with tests, but with quote based delimiters instead of [] which we used in testing, it is a total different ballgame. Sorry for this inconvenience.

Frans Bouma | Lead developer LLBLGen Pro
cfcobio
User
Posts: 11
Joined: 06-Apr-2010
# Posted on: 11-Jun-2010 00:54:34   

I resolved the <unique=true>, I read the XML Schema of nhibernate mapping, and it says unique it is an attribute of element many-to-one, so the final code is

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   assembly="NhfluentTest2.Model"
                   namespace="Testing2.EntityClasses">
                
    <class name="Table3" table="&quot;public&quot;.&quot;table3&quot;" optimistic-lock="version" >
        <composite-id>
            <key-property name="PkP1" column="pk_p1" />
            <key-property name="PkP2" column="pk_p2" />
        </composite-id>
        <many-to-one name="Table2EntityViaFkT2" access="field.camelcase-underscore" fetch="select" unique="true">
            <column name="fk_t2"/>
        </many-to-one>

    </class>
</hibernate-mapping>

but now I have a similar error about 2 columns but only 1 column mapped.

broken column mapping for: Table3EntityViaId.id of: Testing2.EntityClasses.Table2, type component[PkP1,PkP2] expects 2 columns, but 1 were mapped

For now, I'm only playing with the framework, there is no inconvenience for me, also learning to solve these exceptions, they teach me about the internals of the framework and learning from my mistakes.

simple_smile Carlos Duran

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 11-Jun-2010 11:23:22   

The quotes were a dumb mistake from our part, I looked at it yesterday, but didn't ran a test, which I should have done. flushed . Fixed in next build. The unique element is our mistake indeed, it should have been an attribute. Fixed in next build.

Will look into the compound pk-fk issue.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 11-Jun-2010 12:41:05   

ABout the compound PK - FK failing. When a 1:1 pk-pk relationship mapping is emitted it seems the fk/pk side are switched in the mappings (it emits the fk side code in the pk side and vice versa). This of course leads to problematic situations. Seems present for both fluentnh and hbm mappings. It's a situation we overlooked. working on fix.

Hmm... rechecking our code, I think we emit the proper output. Table 3 is the FK side, table 2 is the PK side, so Table3 should get a 'References' call, and Table2 should get a HasOne call. And it does.

Will consult the FluentNH docs to see if I overlooked something.

(edit) seems a bug in FluentNH. When .Constrained isn't specified, it works, when I specify it I get this lame error.

See if I can mail James about this.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 11-Jun-2010 13:43:01   

Bug in NHibernate 2.1.

When I change the mapping to: /// <summary>Represents the mapping of the 'Table3' entity, represented by the 'Table3' class.</summary> public class Table3Map : ClassMap<Table3> { /// <summary>Initializes a new instance of the <see cref="Table3Map"/> class.</summary> public Table3Map() { Table("\"public\".\"table3\""); OptimisticLock.Version(); LazyLoad();

    Id(x => x.PkP1)
        .Access.CamelCaseField(Prefix.Underscore)
        .Column("pk_p1");

    //CompositeId()
    //  .KeyProperty(x => x.PkP1, "pk_p1")
    //  .KeyProperty(x => x.PkP2, "pk_p2");

    References(x=>x.Table2EntityViaFkT2)
        .Access.CamelCaseField(Prefix.Underscore)
        .Unique()
        .Fetch.Select()
        .Columns("fk_t2");

} 

}

it works. When a compound PK is present on the FK side it apparently crashes with a silly error that the PK side flipped, which is of course wrong. I'll see if I can report this to the nhibernate team.

The rest of the issues have been corrected and will be present in the next build (later today)

(edit) issue in NHibernate's JIRA bugtracker: http://216.121.112.228/browse/NH-2223

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 26-Jul-2010 14:43:22   

It turned out we misinterpreted the documentation of nhibernate and forgot an attribute in the hbm files (and call in the fluentnh files). Fixed in next build.

Frans Bouma | Lead developer LLBLGen Pro