-->
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.  [ 5 posts ] 
Author Message
 Post subject: ORA-00904: Invalid Identifier on a get all from table
PostPosted: Tue Dec 30, 2008 10:43 am 
Newbie

Joined: Tue Dec 30, 2008 10:11 am
Posts: 4
I'm getting a ORA-00904: Invalid Identifier when trying to retrieve all items from a table which would appear to be due to an alias being used in the Where clause hibernate generates.

The issue appears to be related to this -> http://opensource.atlassian.com/project ... se/HHH-817 which is set to a minor bug so I I'm not sure if I am simply not understanding a simple workaround?

The basic data access code is all generated using salto-db (which is based on the pattern descibed here -> http://www.hibernate.org/328.html) and does not (as far as I understand it) use a projection as described in the bug report. The code I am running (see blow) is just passing an empty Criteria in order to return all items.

Can anyone help me determine how to avoid this issue? If it is due to the structure of the data model there is an opportunity to alter it should that make my life easier.

The tables in question are

Location
- name (PK)
- other params

and

RouteSection
- location from ( FK to location name)
- location to( FK to location name)
- other params

Thanks
Tom


Hibernate version:
Hibernate 3.3.1.GA

Mapping documents:

- Annotated Class - Originally generated by salto-db-generator, but with a few tweaks since it would not compile due to the two Lists of ModelRouteSection which were generated with the same parameter name (I added the From and To)

Code:
package uk.co.networkrail.elmtree.dataaccesslayer.network.pojo;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
* <p>Pojo mapping TABLE ELMTREE_NETWORKMOD_OWNER_TDP.LOCATION</p>
*
* <p>Generated at Mon Dec 29 16:17:42 GMT 2008</p>
* @author Salto-db Generator v1.0.16 / EJB3
*
*/
@Entity
@Table(name = "LOCATION")
@SuppressWarnings("serial")
public class ModelLocation implements Serializable
{
    /**
     * Attribute name.
     */
    private String name;

    /**
     * Attribute modelLocationType
     */
    private ModelLocationType modelLocationType;

    /**
     * Attribute elr.
     */
    private String elr;

    /**
     * Attribute miles.
     */
    private Integer miles;

    /**
     * Attribute chains.
     */
    private Integer chains;

    /**
     * List of ModelLocationKvp
     */
    private List<ModelLocationKvp> modelLocationKvps = null;

    /**
     * List of ModelRouteSection
     */
    private List<ModelRouteSection> modelRouteSectionsTo = null;

    /**
     * List of ModelRouteSection
     */
    private List<ModelRouteSection> modelRouteSectionsFrom = null;


    /**
     * @return name
     */
    @Basic
    @Id
    @Column(name = "name", length = 50)
    public String getName()
    {
        return name;
    }

    /**
     * @param name new value for name
     */
    public void setName(String name)
    {
        this.name = name;
    }

    /**
     * get modelLocationType
     */
    @ManyToOne
    @JoinColumn(name = "location_type_id")
    public ModelLocationType getModelLocationType()
    {
        return this.modelLocationType;
    }

    /**
     * set modelLocationType
     */
    public void setModelLocationType(ModelLocationType modelLocationType)
    {
        this.modelLocationType = modelLocationType;
    }

    /**
     * @return elr
     */
    @Basic
    @Column(name = "ELR", length = 50)
    public String getElr()
    {
        return elr;
    }

    /**
     * @param elr new value for elr
     */
    public void setElr(String elr)
    {
        this.elr = elr;
    }

    /**
     * @return miles
     */
    @Basic
    @Column(name = "miles")
    public Integer getMiles()
    {
        return miles;
    }

    /**
     * @param miles new value for miles
     */
    public void setMiles(Integer miles)
    {
        this.miles = miles;
    }

    /**
     * @return chains
     */
    @Basic
    @Column(name = "chains")
    public Integer getChains()
    {
        return chains;
    }

    /**
     * @param chains new value for chains
     */
    public void setChains(Integer chains)
    {
        this.chains = chains;
    }

    /**
     * Get the list of ModelLocationKvp
     */
    @OneToMany(mappedBy="modelLocationKvpPK.modelLocation")
    public List<ModelLocationKvp> getModelLocationKvps()
    {
        return this.modelLocationKvps;
    }

    /**
     * Set the list of ModelLocationKvp
     */
    public void setModelLocationKvps(List<ModelLocationKvp> modelLocationKvps)
    {
        this.modelLocationKvps = modelLocationKvps;
    }
    /**
     * Get the list of ModelRouteSection
     */
    @OneToMany(mappedBy="modelLocationTo")
    public List<ModelRouteSection> getModelRouteSectionsTo()
    {
        return this.modelRouteSectionsTo;
    }

    /**
     * Set the list of ModelRouteSection
     */
    public void setModelRouteSectionsTo(List<ModelRouteSection> modelRouteSections)
    {
        this.modelRouteSectionsTo = modelRouteSections;
    }
    /**
     * Get the list of ModelRouteSection
     */
    @OneToMany(mappedBy="modelLocationFrom")
    public List<ModelRouteSection> getModelRouteSectionsFrom()
    {
        return this.modelRouteSectionsFrom;
    }

    /**
     * Set the list of ModelRouteSection
     */
    public void setModelRouteSectionsFrom(List<ModelRouteSection> modelRouteSections)
    {
        this.modelRouteSectionsFrom = modelRouteSections;
    }
}



Code between sessionFactory.openSession() and session.close():

Code:
public List<Location> getLocations() throws NetworkModelItemRollbackException
    {
        List<Location> locations = null;

        // Create a session and start a transaction
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        Transaction transaction = session.beginTransaction();

        try
        {
            // Get the DAO and return all locations
            ModelLocationHibernateDAO locationManager = (ModelLocationHibernateDAO) DAOFactory.DEFAULT.buildModelLocationDAO();
            locationManager.setSession(session);
            locations = buildLocations(locationManager.findAll());
            transaction.commit();
        } catch (HibernateException he)
        {
            transaction.rollback();
            NetworkModelItemRollbackException rollback = new NetworkModelItemRollbackException("Failed to retrieve all Locations", he);
            mLogger.logMessage(rollback, LogLevel.ERROR);
            throw rollback;
        } finally
        {
            // Always close the session if it is open
            if (session.isOpen())
            {
                session.close();
            }
        }

        return locations;
    }



locationManager.findAll() code shown below.....
Code:
public List<T> findAll()
    {
        return findByCriteria();
    }

    /**
     * Use this inside subclasses as a convenience method.
     */
    @SuppressWarnings("unchecked")
    protected List<T> findByCriteria(Criterion... criterion)
    {
        Criteria crit = getSession().createCriteria(getPersistentClass());
        for (Criterion c : criterion)
        {
            crit.add(c);
        }
        return crit.list();
    }


Full stack trace of any exception that occurs:
1876 [main] ERROR org.hibernate.util.JDBCExceptionReporter - ORA-00904: "MODELLOCAT2_"."LOCATION_TYPE_ID": invalid identifier

Name and version of the database you are using:
Oracle 10.2

The generated SQL (show_sql=true):
Code:
Hibernate:
select this_.name as name0_1_,
         this_.chains as chains0_1_,
         this_.ELR as ELR0_1_,
         this_.miles as miles0_1_,
         this_.location_type_id as location5_0_1_,                       
         modellocat2_.location_type_id as location1_2_0_,
         modellocat2_.description as descript2_2_0_
from LOCATION this_, LOCATION_TYPE modellocat2_
where this_.location_type_id=modellocat2_.location_type_id(+)


Debug level Hibernate log excerpt:
(Not sure what I can provide here above that already shown above)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 31, 2008 7:14 am 
Newbie

Joined: Tue Dec 30, 2008 10:11 am
Posts: 4
On further inspection this isn't related to the bug listed since it is clearly the aliased table in the where clause that is causing the problem and this should be perfectly allowable as far as I understand it since the From should be processed before the Where, hence the alias is known.

I'm pretty sure this must be a simple mistake on my part, but would really appreciate some help in solving it.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 31, 2008 9:14 am 
Newbie

Joined: Tue Dec 30, 2008 10:11 am
Posts: 4
In case anyone else has this issue...

It would appear that the database scripts had been written as below

Code:
CREATE TABLE "LOCATION"
(
   "name"              VARCHAR2(50) NOT NULL,
    etc...


Removing the " " solved the issue.


Top
 Profile  
 
 Post subject: Re: ORA-00904: Invalid Identifier on a get all from table
PostPosted: Fri Sep 16, 2011 2:49 am 
Newbie

Joined: Fri Sep 16, 2011 2:40 am
Posts: 1
Hi frnds,
I came up with same error.
Code:
ORA-00904: "SYSLASTNUM0_"."TYPE": invalid identifier


After reading the post of tomp, v understood that our DB script for all tables has defined columns b/w double quotes.
Code:
"type"


But, the issue is v cannot change the DB scripts.
V are in need of solution urgently.

Is there a way to bypass
Quote:
"
char in HQL language.

Kindly reply. Thanks in advance.


Top
 Profile  
 
 Post subject: Re: ORA-00904: Invalid Identifier on a get all from table
PostPosted: Mon Mar 05, 2012 5:00 am 
Newbie

Joined: Mon Mar 05, 2012 4:48 am
Posts: 1
I was getting this similar error for my hibernate query like this
"delete from TableOne where id NOT IN (select someColumn from TableTwo) AND creationDate <= :paramDate"

It was giving me InvalidIdentifier for TableOne_.CREATION_DATE. Though column was present and everything was at its place. Moreover code was working fine earlier with Jdk 1.4 & Hibernate 2.1.8 version. But after migrating the code to Jdk 1.6 & Hibernate 3.2.3 it was giving this error.

I tried following change & it worked without any problem.
"delete from TableOne where creationDate <= :paramDate AND id NOT IN (select someColumn from TableTwo)"


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