-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Problem in generated sql with @SecondaryTables
PostPosted: Thu Jan 10, 2008 12:08 pm 
Newbie

Joined: Thu Jan 10, 2008 11:34 am
Posts: 2
Hi all,
I've a little problem with hibernate accessing an entity that has more than one Secondary Table.

My Entity is defined like this:


Code:
@Entity
@Table(name="tab1")
@SecondaryTables({
  @SecondaryTable(name="tab2"),
  @SecondaryTable(name="tab3")
})
public MyObject {

@Id
int id;

@Basic
int field1;

@Column(table="tab2")
int field2;

@Column(table="tab3")
int field3;

...
...


}


the generated query is like this one:

Code:
SELECT .... FROM tab1 left outer join tab2 on .... left outer join tab3 on ....


This sintax is not supported by the database I'm using (MSAccess. I know it's not officially supported but I cannot change it)

In order to have a working query it should be necessary to enclose the joins in parenthesis, like this:

Code:
SELECT .... FROM ((tab1 left outer join tab2 on ....) left outer join tab3 on ....)


Is it possible to obtain this behaviour, even extending some hibernate class?

I've also tried adding
@org.hibernate.annotations.Table(appliesTo="tab1", fetch=FetchMode.SELECT) annotation but the resulting query is not changed.

I was expecting to have 3 different selects instead of one with outer joins but this didn't appened.

Any Hint?

Best Regards
Fabio


Hibernate version:
3.3GA


Top
 Profile  
 
 Post subject: Solve it via extending a hibernate class
PostPosted: Thu Jan 17, 2008 7:25 am 
Beginner
Beginner

Joined: Wed Jan 16, 2008 8:16 am
Posts: 23
Hi,

I have also used the @Table annotation to modify the join behaviour; but it doesnt work.

The only possibility I found is to change the join behaviour. Therefore you need to extend the database dialect in the hibernate.cfg.xml file;
Code:
<property name="dialect">your_own_dialect_class</property>
. Your dialect class need simply extend the access dialect and override the
Code:
public JoinFragment createOuterJoinFragment()
method, where you create you own join fragment class. Inside this class you override the
Code:
addJoin
method and you ignore the outer joins.

I hope I can help you.

Best regard,
michi


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 17, 2008 7:42 am 
Newbie

Joined: Thu Jan 10, 2008 11:34 am
Posts: 2
Thank you Michael for your reply.

I already have my own MSDialect class but overriding the create(outer)JoinFragment cannot help me. With this method I found no way to access the actual query string where the "From myTable" part is present.
I need it to insert a "(" just after the "From myTable" fragment when a join is created.

Actually I've solved my problem in a deeper way...I wrote a MS Access JDBC implementation that uses JACOB COM bridge and ADO and that works with Hibernate 3.3. My JDBC Driver parses the sql created by Hibernate and add the required parenthesis.

Actually it's just a ONE-DAY code but it does the work.

Best Regards
Fabio


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.