-->
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.  [ 8 posts ] 
Author Message
 Post subject: referencedColumnName containing an underscore
PostPosted: Mon Dec 04, 2006 9:34 pm 
Newbie

Joined: Mon Dec 04, 2006 8:57 pm
Posts: 4
Location: US, New Jersey, Piscataway
First off thanks to everybody at Hibernate (both devTeam and (Forum)supportTeam), you are really doing an amazing job.

My "finger stuck in a bottle" is, that as long as i have an underscore in the name of the column towards which i have a foreign-key (e.g. referencedColumnName = "LSC_ID"), I am getting a
"org.hibernate.MappingException: Unable to find column with logical name: LSC_ID in org.hibernate.mapping.Table(DD.LOGLVL_T) and its related supertables and secondary tables".

Once I remove the underscore on both sides (Oracle and annotations) it works fine, but if i add the underscore back it craps out on me.

I have a naming policy to respect, therefore I have to stick to the underscores for all primary/alternate/foreign-key columns.
Is there a way to avoid the exception, while using underscores for referencedColumns?

Thank you in advance,
Richard

Hibernate version:
Hibernate 3.2.1, with JPA using Annotations

Full stack trace of any exception that occurs:
org.hibernate.MappingException: Unable to find column with logical name: LSC_ID in org.hibernate.mapping.Table(DD.LOGLVL_T) and its related supertables and secondary tables
at org.hibernate.cfg.Ejb3JoinColumn.checkReferencedColumnsType(Ejb3JoinColumn.java:364)
at org.hibernate.cfg.BinderHelper.createSyntheticPropertyReference(BinderHelper.java:88)
at org.hibernate.cfg.FkSecondPass.doSecondPass(FkSecondPass.java:63)
at org.hibernate.cfg.AnnotationConfiguration.processFkSecondPassInOrder(AnnotationConfiguration.java:428)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:286)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1112)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1211)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:154)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:847)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:178)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:235)
... 21 more

Name and version of the database you are using:
Tested on both Oracle 10g R2 (HP-UX) and Oracle 10g R2 (RHEL 4.3)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 05, 2006 5:00 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
I use underscore frequently with Oracle 9. I would not expect a problem here. Can you post an example mapping with test code?

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject: no _ in composite PK fields if composite FK points to them
PostPosted: Tue Dec 05, 2006 8:19 pm 
Newbie

Joined: Mon Dec 04, 2006 8:57 pm
Posts: 4
Location: US, New Jersey, Piscataway
LaLiLuna thank you kindly for getting back to me on such short notice.

I've recreated the test environment from scratch and retested my findings, ending with the same conclusion.

As long as i have a composite foreign key pointing to a composite primary key, the primary key's columns cannot contain "_"(underscore) or else I get a :

Quote:
org.hibernate.MappingException: Unable to find column with logical name: PC1_ID in org.hibernate.mapping.Table(DD.PKTBL_T) and its related supertables and secondary tables


Please see the code below.

SQL DDL for the two tables :

Code:
create table PKTBL_T  (
   PC1_ID               INTEGER                         not null,
   PC2_ID               INTEGER                         not null,
   DESCR                VARCHAR2(256 BYTE)
);

alter table PKTBL_T add constraint PK_PKTBL_T       primary key (PC1_ID, PC2_ID);
alter table PKTBL_T add constraint AK_ID_AK_PKTBL_T unique      (PC1_ID);

create table FKTBL_T  (
   ID                   INTEGER                         not null,
   FC1_ID               INTEGER,
   FC2_ID               INTEGER,
   MSG                  VARCHAR2(256 BYTE)
);

alter table FKTBL_T add constraint PK_FKTBL_T  primary key         (ID);
alter table FKTBL_T add constraint LG_LGLVL_FK foreign key         (FC1_ID, FC2_ID)
                                               references  PKTBL_T (PC1_ID, PC2_ID);


Annotated Java classes.

Class for PKTBL_T ("primary key" table, towards which the foreign key points):

Code:
@Entity
@IdClass(PktblTEntityPK.class)
@Table(schema = "DD", name = "PKTBL_T")
public class PktblTEntity
{
  private BigInteger pc1Id;
  private BigInteger pc2Id;
  private String descr;

  @Id
  @Column(name = "PC1_ID", nullable = false, length = 22)
  public BigInteger getPc1Id() {...}
  public void setPc1Id(BigInteger pc1Id) {...}

  @Id
  @Column(name = "PC2_ID", nullable = false, length = 22)
  public BigInteger getPc2Id() {...}
  public void setPc2Id(BigInteger pc2Id) {...}

  @Basic
  @Column(name = "DESCR", length = 256)
  public String getDescr() {...}
  public void setDescr(String descr) {...}
 
}

public class PktblTEntityPK implements Serializable
{
  private java.math.BigInteger pc1Id;
  private java.math.BigInteger pc2Id;

  /* hashCode,equals and getters/setters for pc1Id/pc2Id */
}


Class for FKTBL_T ("foreign key" table, containing the foreign key that points toward PKTBL_T):

Code:
@Entity
@Table(schema = "DD", name = "FKTBL_T")
public class FktblTEntity
{
  private BigInteger id;
  private String msg;
  private PktblTEntity fkEnt;

  @Id
  @Column(name = "ID", nullable = false, length = 22)
  public BigInteger getId() {...}
  public void setId(BigInteger id) {...}

  @Basic
  @Column(name = "MSG", length = 256)
  public String getMsg() {...}
  public void setMsg(String msg) {...}

  @OneToOne
  @JoinColumns({@JoinColumn(name = "FC1_ID", referencedColumnName = "PC1_ID"), @JoinColumn(name = "FC2_ID", referencedColumnName = "PC2_ID")})
  public PktblTEntity getFkEnt() {...}
  public void setFkEnt(PktblTEntity fkEnt) {...}
}


Please let me know if you need more detail. I'm trying to keep it as short as possible.

Thank you again for all your time and precious advices. Your effort is highly appreciated,
Richard


Top
 Profile  
 
 Post subject: Toplink works fine
PostPosted: Tue Dec 05, 2006 9:46 pm 
Newbie

Joined: Mon Dec 04, 2006 8:57 pm
Posts: 4
Location: US, New Jersey, Piscataway
An update,

I successfuly tested the same things with Toplink a minute ago.
And I can use "_" in composite primary key and no exception gets generated.

This does confirm me that it may be something in Hibernate.

Thank you again,
Richard


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 06, 2006 4:13 pm 
Newbie

Joined: Wed Dec 06, 2006 4:04 pm
Posts: 8
Location: New Hampshire
I have seen this problem, also, and it was driving me crazy.

I had an underline in the name of an id column in a supertype table with a self-referencing relationship. The Hibernate compiler that was invoked when calling the EntityManager consistently told me that a column of the name RESOURCE_ID did not exist in that class, and despite all my efforts, I could not get it to like that class until I renamed the id column.

Have they had you post this as a bug? Did you find a work around?
J


Top
 Profile  
 
 Post subject: no workaround
PostPosted: Wed Dec 06, 2006 4:54 pm 
Newbie

Joined: Mon Dec 04, 2006 8:57 pm
Posts: 4
Location: US, New Jersey, Piscataway
J,

nobody contacted me so far.

At least for me it is a big issue as i have to respect certain naming conventions, and now i need to break them for source tables that have composite foreign keys point.

When/if asked I will file a testCase into JIRA and hopefuly this will be fixed.
I have everything prepared.

At this point I didn't find any workaround for this. If you do please post a message on this topic, as this is really important for me.

Richard


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 06, 2008 11:44 pm 
Newbie

Joined: Wed Feb 06, 2008 9:36 pm
Posts: 1
Hello,

I have just stepped into this while trying to make my project work with Hibernate. Currently we're using toplink but being a hibernate fan for long time I'd love to move to hib but this is a big problem for us now. Can't move forward.

Thanks.

Bipul.


Top
 Profile  
 
 Post subject: Re: referencedColumnName containing an underscore
PostPosted: Wed Jun 10, 2009 2:35 pm 
Newbie

Joined: Tue Jun 09, 2009 10:52 pm
Posts: 9
I was having the same issue with Hibernate version 3.2.6. After upgrading to 3.3.1 everything worked fine. Good luck all!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.