-->
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: Cast and joincolumn
PostPosted: Wed Oct 12, 2011 12:40 pm 
Newbie

Joined: Wed Oct 12, 2011 12:34 pm
Posts: 3
Hello,

I have a problem

My request

Code:
SELECT *
  FROM M m
  inner join T t on t.tid = cast (m.id as varchar(255));


I don't know how to create the cast with annotation

Code:
@Entity
public class M{

...

@OneToOne(fetch = FetchType.LAZY)
@JoinTable(name = "T", joinColumns = @JoinColumn(name = "tid", referencedColumnName = "cast (id as varchar(255))"))
private T t;


It doesn't work. Please need help. How to join the table M with T

EDIT: Just for information: id is a bigint and tid is a varchar


Top
 Profile  
 
 Post subject: Re: Cast and joincolumn
PostPosted: Thu Oct 13, 2011 8:08 am 
Newbie

Joined: Wed Oct 12, 2011 12:34 pm
Posts: 3
Quote:

@OneToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "id", referencedColumnName = "tid")
private T t;


With this syntax i have no error when i execute this HQL query:

Quote:
select m from M as m


But Hibernate doesn't get the T element. I can't do the join between the 2 table.


Please it's really important. How can i do a join on column with different type?


Top
 Profile  
 
 Post subject: Re: Cast and joincolumn
PostPosted: Thu Oct 13, 2011 10:23 am 
Newbie

Joined: Wed Oct 12, 2011 12:34 pm
Posts: 3
I try to use @JoinColumnsOrFormulas but

Code:
@ManyToOne
@JoinColumnsOrFormulas({ @JoinColumnOrFormula(formula = @JoinFormula(value = "cast (t as bigint)", referencedColumnName = "id")) })
@Fetch(FetchMode.JOIN)
private T t;


But i have an error on SQL Syntax

I try this

Code:
@ManyToOne
@JoinColumnsOrFormulas({ @JoinColumnOrFormula(formula = @JoinFormula(value = "cast (id as varchar(255))", referencedColumnName = "tid")) })
@Fetch(FetchMode.JOIN)
private T t;

but i have this error

Quote:

referencedColumnNames(tid) of com.test.M.t referencing com.test.T not mapped to a single property


Someone can help me please.


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.