-->
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.  [ 6 posts ] 
Author Message
 Post subject: Column found in more than one FROM list table.
PostPosted: Thu Sep 16, 2010 2:57 am 
Newbie

Joined: Thu Sep 16, 2010 2:38 am
Posts: 3
Hi guys,
Need some help, I've been battling this for days.
I have 2 tables: "Item", "Log" (this is a one-to-many relationship)

Now the entity beans look like this:

Code:
@Entity
@IdClass(ItemPK.class)
@Table(name = "Item")
public class Item implements Serializable {
   private static final long serialVersionUID = 1L;
   
   @Id private Integer service_no;
   @Id private String mnemonic_type;
   private String header;
   private String member;
   private String service_type;
   private String dept_name;
   private String username;
   private String phone_no;
   private String subject;
   private String description;
   private String priority;
   private String service_status;
   private Date date_created;
   private String responsible_officer;
   private Date date_started;
   private Date date_completed;
   private Date date_file_attached;
   private Date timestamp;
   private String case_no;
   
   @MapsId("Log")
   @OneToMany(fetch = FetchType.EAGER, targetEntity = Log.class)
        @Fetch(value = FetchMode.JOIN)
   //@Fetch(value = FetchMode.SELECT)
   @JoinColumns({
      @JoinColumn(name = "service_no", referencedColumnName = "service_no"),
      @JoinColumn(name = "mnemonic_type", referencedColumnName = "mnemonic_type")
   })
   @OrderBy("timestamp desc")
   private List<Log> Logs;
   
   public Item() {
      
   }
   
   public Integer getService_no() {
      return service_no;
   }
   
   public void setService_no(Integer service_no) {
      this.service_no = service_no;
   }
   
   public String getMnemonic_type() {
      return mnemonic_type;
   }
   
   public void setMnemonic_type(String mnemonic_type) {
      this.mnemonic_type = mnemonic_type;
   }
   
   public String getHeader() {
      return header;
   }
   
   public void setHeader(String header) {
      this.header = header;
   }

   public String getMember() {
      return member;
   }

   public void setMember(String member) {
      this.member = member;
   }

   public String getService_type() {
      return service_type;
   }

   public void setService_type(String service_type) {
      this.service_type = service_type;
   }

   public String getDept_name() {
      return dept_name;
   }

   public void setDept_name(String dept_name) {
      this.dept_name = dept_name;
   }

   public String getUsername() {
      return username;
   }

   public void setUsername(String username) {
      this.username = username;
   }

   public String getPhone_no() {
      return phone_no;
   }

   public void setPhone_no(String phone_no) {
      this.phone_no = phone_no;
   }

   public String getSubject() {
      return subject;
   }

   public void setSubject(String subject) {
      this.subject = subject;
   }

   public String getDescription() {
      return description;
   }

   public void setDescription(String description) {
      this.description = description;
   }

   public String getPriority() {
      return priority;
   }

   public void setPriority(String priority) {
      this.priority = priority;
   }

   public String getService_status() {
      return service_status;
   }

   public void setService_status(String service_status) {
      this.service_status = service_status;
   }

   @JsonSerialize(using = DateSerializer.class)
   public Date getDate_created() {
      return date_created;
   }

   public void setDate_created(Date date_created) {
      this.date_created = date_created;
   }

   public String getResponsible_officer() {
      return responsible_officer;
   }

   public void setResponsible_officer(String responsible_officer) {
      this.responsible_officer = responsible_officer;
   }

   @JsonSerialize(using = DateSerializer.class)
   public Date getDate_started() {
      return date_started;
   }

   public void setDate_started(Date date_started) {
      this.date_started = date_started;
   }

   @JsonSerialize(using = DateSerializer.class)
   public Date getDate_completed() {
      return date_completed;
   }

   public void setDate_completed(Date date_completed) {
      this.date_completed = date_completed;
   }

   @JsonSerialize(using = DateSerializer.class)
   public Date getDate_file_attached() {
      return date_file_attached;
   }

   public void setDate_file_attached(Date date_file_attached) {
      this.date_file_attached = date_file_attached;
   }

   @JsonSerialize(using = DateSerializer.class)
   public Date getTimestamp() {
      return timestamp;
   }

   public void setTimestamp(Date timestamp) {
      this.timestamp = timestamp;
   }

   public String getCase_no() {
      return case_no;
   }

   public void setCase_no(String case_no) {
      this.case_no = case_no;
   }

   public List<Log> getLogs() {
      return Logs;
   }

   public void setLogs(List<Log> Logs) {
      this.Logs = Logs;
   }
}


And here too...
Code:
@Entity
@IdClass(LogPK.class)
@Table(name = "Log")
public class Log implements Serializable {
   private static final long serialVersionUID = 1L;
   @Id private Integer service_no;
   @Id private String mnemonic_type;
   private String username;
   private String service_status;
   private String responsible_officer;
   private String progress_notes;
   @Id private Date timestamp;
   private String notes_type;
   
   public Log() {
      
   }

   public Integer getService_no() {
      return service_no;
   }

   public void setService_no(Integer service_no) {
      this.service_no = service_no;
   }

   public String getMnemonic_type() {
      return mnemonic_type;
   }

   public void setMnemonic_type(String mnemonic_type) {
      this.mnemonic_type = mnemonic_type;
   }

   public String getUsername() {
      return username;
   }

   public void setUsername(String username) {
      this.username = username;
   }

   public String getService_status() {
      return service_status;
   }

   public void setService_status(String service_status) {
      this.service_status = service_status;
   }

   public String getResponsible_officer() {
      return responsible_officer;
   }

   public void setResponsible_officer(String responsible_officer) {
      this.responsible_officer = responsible_officer;
   }

   public String getProgress_notes() {
      return progress_notes;
   }

   public void setProgress_notes(String progress_notes) {
      this.progress_notes = progress_notes;
   }

   @JsonSerialize(using = DateSerializer.class)
   public Date getTimestamp() {
      return timestamp;
   }

   public void setTimestamp(Date timestamp) {
      this.timestamp = timestamp;
   }

   public String getNotes_type() {
      return notes_type;
   }

   public void setNotes_type(String notes_type) {
      this.notes_type = notes_type;
   }
}


Now the joins on these 2 entities are fine.
When I go to do a load on Item.class through a Criteria, here's the SQL that Hibernate spits out...

Hibernate:
select
this_.mnemonic_type as mnemonic1_29_1_,
this_.service_no as service2_29_1_,
this_.case_no as case3_29_1_,
this_.date_completed as date4_29_1_,
this_.date_created as date5_29_1_,
this_.date_file_attached as date6_29_1_,
this_.date_started as date7_29_1_,
this_.dept_name as dept8_29_1_,
this_.description as descript9_29_1_,
this_.header as header29_1_,
this_.member as member29_1_,
this_.phone_no as phone12_29_1_,
this_.priority as priority29_1_,
this_.responsible_officer as respons14_29_1_,
this_.service_status as service15_29_1_,
this_.service_type as service16_29_1_,
this_.subject as subject29_1_,
this_.timestamp as timestamp29_1_,
username as username29_1_,
srrequestl2_.mnemonic_type as mnemonic1_29_3_,
srrequestl2_.service_no as service2_29_3_,
srrequestl2_.mnemonic_type as mnemonic1_3_,
srrequestl2_.service_no as service2_3_,
srrequestl2_.timestamp as timestamp3_,
srrequestl2_.mnemonic_type as mnemonic1_30_0_,
srrequestl2_.service_no as service2_30_0_,
srrequestl2_.timestamp as timestamp30_0_,
srrequestl2_.notes_type as notes4_30_0_,
srrequestl2_.progress_notes as progress5_30_0_,
srrequestl2_.responsible_officer as responsi6_30_0_,
srrequestl2_.service_status as service7_30_0_,
username as username30_0_
from
item this_
left outer join
log srrequestl2_
on this_.mnemonic_type=srrequestl2_.mnemonic_type
and this_.service_no=srrequestl2_.service_no
where
this_.mnemonic_type=?
and this_.case_no=?
order by
srrequestl2_.timestamp desc

and here's the error...

35859 [http-8080-4] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 2101, SQLState: 5000A
35859 [http-8080-4] ERROR org.hibernate.util.JDBCExceptionReporter - line 1, Column 'username' found in more than one FROM list table.

Does anyone find that SQL weird (check the BOLD lines)
Now mind you, when I re-run this with FetchMode.SELECT - it works perfectly - but there is a serious performance hit with running it like this. I would like to run it as Fetch.JOIN.

Help, what am I doing wrong?
All help would be appreciated.


Top
 Profile  
 
 Post subject: Re: Column found in more than one FROM list table.
PostPosted: Thu Sep 16, 2010 3:06 am 
Regular
Regular

Joined: Fri Aug 06, 2010 1:49 am
Posts: 102
Location: shynate26@gmail.com
Error is because Username present in 2 entities. In Fetch as select it would be different , here it is different. So if you paste the sql,hql it would be answerable

_________________

Cheers!
Shynate
mailto:shynate26@gmail.com
www.CSSCORP.com


Top
 Profile  
 
 Post subject: Re: Column found in more than one FROM list table.
PostPosted: Thu Sep 16, 2010 3:14 am 
Newbie

Joined: Thu Sep 16, 2010 2:38 am
Posts: 3
shynate26 wrote:
Error is because Username present in 2 entities. In Fetch as select it would be different , here it is different. So if you paste the sql,hql it would be answerable


Thanks for the reply.
I agree with your assertion. The SQL as Hibernates has outputted, if run in any standard DB tool would also throw an error. My problem is that I have other variables in both entities that are duplicates and they seem to be "prefixed" in the SQL just fine, except the "Username" column.

Does anyone know why this happens?
Is "Username" a reserved word?

Thanks


Top
 Profile  
 
 Post subject: Re: Column found in more than one FROM list table.
PostPosted: Thu Sep 16, 2010 3:54 am 
Regular
Regular

Joined: Thu May 07, 2009 5:56 am
Posts: 94
Location: Toulouse, France
and what's happening if you customize one of the "username" columns?
Code:
public class Log ....
{
...
@Column(name = "log_user_name")
private String username;
}

_________________
everything should be made as simple as possible, but not simpler (AE)


Top
 Profile  
 
 Post subject: Re: Column found in more than one FROM list table.
PostPosted: Thu Sep 16, 2010 6:48 pm 
Newbie

Joined: Thu Sep 16, 2010 2:38 am
Posts: 3
Well, I can't do ...

@Column(name = "log_user_name")
private String username

in the Log.class entity unless I am prepared to change the "username" column in the DB. Now I can't do that because it's a legacy application. My question is why Hibernate, when generating the SQL for the 2 entities, prefixes all of the columns (including any columns that exist in both entities) except the "username" column? Is username a special, keyword or something?

Help pls.


Top
 Profile  
 
 Post subject: Re: Column found in more than one FROM list table.
PostPosted: Mon Sep 20, 2010 1:22 am 
Regular
Regular

Joined: Fri Aug 06, 2010 1:49 am
Posts: 102
Location: shynate26@gmail.com
Now , hibernate annotation it seems not able to differentiate the column names. Here Item entity has property username mapped to username. Log entity has username mapped to log_user_name. Here it is supposed to fetch Log entity. log_user_name but it did not fetch. Better some senior member can answer this scenario.

_________________

Cheers!
Shynate
mailto:shynate26@gmail.com
www.CSSCORP.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.