Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Null attribute classification

Hi Carl,

Hopefully some of the forum users that are more familiar with Spring can help you with what appear to be a config issue. Otherwise, I'll try to track down and example for you.

  Here's what I can tell you.

1. It looks like the EntityManager used in Spring is not aware of your Entities (it cannot parse any of your JPQL because it doesn't know about the Entities)

2. Because you are seeing some EclipseLink logging issues related to deployment, I believe EclipseLink is finding your Entities.

3. It is likely that for some reason, your spring application does not know about your persistence unit. I am not certain what you have to do to make it aware of it.

4. It would be a good idea to ensure that your persistence unit is packaged as JPA expects it. i.e. A jar with your Entities at the base, your persistence.xml in the META-INF directory and your orm.xml files either called META-INF/orm.xml or included in your jar in the directory specified in your persistence.xml.

-Tom

Carl Hall wrote:
From the results below, it seems like EclipseLink doesn't know about my classes. I've had errors in my orm.xml mappings that EL told me about so I know it is reading the files. Is there something else I can check to see why I can't get this to work?



On Fri, Oct 24, 2008 at 09:11, Carl Hall <carl.hall@xxxxxxxxx <mailto:carl.hall@xxxxxxxxx>> wrote:

    I tried running the following queries with results noted.  I've
    attached my orm.xml in hopes it will show my error somewhere.

    *List<Poll> pollList = (List<Poll>) getJpaTemplate().find("select p
    from Poll p");*
    /*
    results:

    Internal Exception: java.sql.SQLException: Unexpected token: FROM in statement [SELECT  FROM POLL_POLL]
    Error Code: -11
    Call: SELECT  FROM POLL_POLL
    Query: ReadAllQuery(org.sakaiproject.poll.model.Poll)


Local Exception Stack: Exception [EclipseLink-4002] (Eclipse Persistence Services - 1.0.1 (Build 20080905)): org.eclipse.persistence.exceptions.DatabaseException
    Internal Exception: java.sql.SQLException: Unexpected token: FROM in statement [SELECT  FROM POLL_POLL]


    Error Code: -11
    Call: SELECT  FROM POLL_POLL
    Query: ReadAllQuery(org.sakaiproject.poll.model.Poll)
    */

    *List<Poll> pollList = (List<Poll>) getJpaTemplate().find("select p
    from Poll p where p.id <http://p.id> = ?1", id);*
    /*
    results:


    Caused by: Exception [EclipseLink-8030] (Eclipse Persistence
    Services - 1.0.1 (Build 20080905)):
    org.eclipse.persistence.exceptions.JPQLException

    Exception Description: Error compiling the query [select p from Poll p where p.id <http://p.id> = ?1], line 1, column 29: unknown state or association field [id] of class [org.sakaiproject.poll.model.Poll].


    */

    *List<Poll> pollList = (List<Poll>)
    getJpaTemplate().findByNamedQuery("Poll.findAllPolls", siteId);*
    /*
    results:

    NamedQuery of name: Poll.findAllPolls not found.; nested exception is java.lang.IllegalArgumentException: NamedQuery of name: Poll.findAllPolls not found.


    org.springframework.dao.InvalidDataAccessApiUsageException: NamedQuery of name: Poll.findAllPolls not found.; nested exception is java.lang.IllegalArgumentException: NamedQuery of name: Poll.findAllPolls not found.
    Caused by: java.lang.IllegalArgumentException: NamedQuery of name: Poll.findAllPolls not found.


    */




    On Thu, Oct 23, 2008 at 15:15, Carl Hall <carl.hall@xxxxxxxxx
    <mailto:carl.hall@xxxxxxxxx>> wrote:

        Poll.siteId is a String.

        This is the code I run to get the error.  I'll try the queries
        you've noted and respond with the results as soon as I have them.

        public List<Poll> findAllPolls(String siteId)
            {
                List<Poll> pollList = (List<Poll>) getJpaTemplate().find(
                        "select p from Poll p where p.siteId = ?1 order
        by p.creationDate desc", siteId);
                return pollList;

            }


        On Thu, Oct 23, 2008 at 15:04, Tom Ware <tom.ware@xxxxxxxxxx
        <mailto:tom.ware@xxxxxxxxxx>> wrote:

            What is the Java type of siteId?

            Do the following queries run successfully?

            select p from Poll p where p.owner = ?1
            select p from Poll p where p.id <http://p.id> = ?1

            Can you post the snippet of code you use to obtain and run
            your query?

            -Tom


            Carl Hall wrote:

                Responses inline...


                On Thu, Oct 23, 2008 at 14:21, Tom Ware
                <tom.ware@xxxxxxxxxx <mailto:tom.ware@xxxxxxxxxx>
                <mailto:tom.ware@xxxxxxxxxx
                <mailto:tom.ware@xxxxxxxxxx>>> wrote:

                   How does you persistence.xml look?


                <?xml version="1.0" encoding="UTF-8"?>
                <persistence version="1.0"
                xmlns="http://java.sun.com/xml/ns/persistence";
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
                http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd";>
                   <persistence-unit name="default"
                transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>

<mapping-file>org/sakaiproject/poll/jpa/Option.orm.xml</mapping-file> <mapping-file>org/sakaiproject/poll/jpa/Poll.orm.xml</mapping-file> <mapping-file>org/sakaiproject/poll/jpa/Vote.orm.xml</mapping-file>

<exclude-unlisted-classes>true</exclude-unlisted-classes>

                       <properties>
                           <property
                name="eclipselink.jdbc.write-connections.min" value="1" />
                           <property
                name="eclipselink.jdbc.read-connections.min" value="1" />
                           <property name="eclipselink.logging.level"
                value="FINE" />
                           <property
                name="eclipselink.logging.timestamp" value="false" />
                           <property name="eclipselink.logging.session"
                value="false" />
                           <property name="eclipselink.logging.thread"
                value="false" />
                           <property
                name="eclipselink.logging.exceptions" value="false" />
                           <property name="eclipselink.ddl-generation"
                value="drop-and-create-tables" />
                           <property
                name="eclipselink.ddl-generation.output-mode"
                value="both" />
                       </properties>
                   </persistence-unit>
                </persistence>
What does your deployment archive look like? Where
                is the
                   persistence.xml? Where is the orm.xml?


                My persistence file is located as noted above in a jar
                in shared/lib of Tomcat along with
                persistence-api-1.0.jar and eclipselink-1.0.1.jar.  I'm
                pretty sure my orm.xml files are loading because I had
                lots of validation errors from EclipseLink about field
                names not existing in the class (I'm converting from
                hibernate and not all getter names == field names).
                 After I got through the field name mismatches, I
                arrived at this point.  I also see notes in the log like
                "[EL Config]: The access type for the persistent class
                [class org.sakaiproject.poll.model.Poll] is set to
                PROPERTY."

                I use Spring to create my EntityManager with the
                following bean:

                   <bean
                id="org.sakaiproject.springframework.orm.jpa.EntityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
                       <property name="dataSource"
                ref="javax.sql.DataSource" />
                       <property name="jpaVendorAdapter"
                ref="org.sakaiproject.springframework.orm.jpa.vendor.JpaVendorAdapter"
                />
                       <property name="loadTimeWeaver"
                ref="org.sakaiproject.springframework.instrument.classloading.LoadTimeWeaver"
                />
                       <property name="persistenceXmlLocation"
                value="classpath:/org/sakaiproject/poll/jpa/persistence.xml"
                />
                   </bean>


                   Carl Hall wrote:

                       I get the following error when trying to load up
                my orm.xml files:

                       Caused by: Exception [EclipseLink-8030] (Eclipse
                Persistence
                       Services - 1.0.1 (Build 20080905)):
                       org.eclipse.persistence.exceptions.JPQLException
                       Exception Description: Error compiling the query
                [select p from
                       Poll p where p.siteId = ?1 order by
                p.creationDate desc], line
                       1, column 29: unknown state or association field
                [siteId] of
                       class [org.sakaiproject.poll.model.Poll].
                          at
org.eclipse.persistence.exceptions.JPQLException.unknownAttribute(JPQLException.java:450)
                          at
org.eclipse.persistence.internal.jpa.parsing.DotNode.validate(DotNode.java:77)
                          at
org.eclipse.persistence.internal.jpa.parsing.Node.validate(Node.java:91)
                          at
org.eclipse.persistence.internal.jpa.parsing.BinaryOperatorNode.validate(BinaryOperatorNode.java:34)
                          at
org.eclipse.persistence.internal.jpa.parsing.EqualsNode.validate(EqualsNode.java:41)
                          at
org.eclipse.persistence.internal.jpa.parsing.WhereNode.validate(WhereNode.java:34)
                       <snip/>

                       siteId is in my mapping definition for Poll (see
                below) and I
                       don't get any errors when starting up the
                application just when
                       I try to call the query noted above.  I've walked
                the code down
                       to the point where
                TypeHelperImpl.getType(DatabaseMapping)
                       eventually has "type =
                mapping.getAttributeClassification()"
                       which leaves type as null.  What can I do to get
                this type to
                       not be null?

                       Part of Poll.orm.xml:
                       <entity metadata-complete="true" name="Poll"
                       class="org.sakaiproject.poll.model.Poll">
                          <table name="POLL_POLL"/>
                          <attributes>
                            <id name="id">
                              <column name="POLL_ID"/>
                              <generated-value strategy="SEQUENCE"
                       generator="POLL_POLL_ID_SEQ"/>
                              <sequence-generator name="POLL_POLL_ID_SEQ"
                       sequence-name="POLL_POLL_ID_SEQ"/>
                            </id>
                            <basic name="owner">
                              <column name="POLL_OWNER" nullable="false"/>
                            </basic>
                            <basic name="siteId">
                              <column name="POLL_SITE_ID" nullable="false"/>
                            </basic>
                        </attributes>
                       </entity>


------------------------------------------------------------------------

                       _______________________________________________
                       eclipselink-users mailing list
                       eclipselink-users@xxxxxxxxxxx
                <mailto:eclipselink-users@xxxxxxxxxxx>
                <mailto:eclipselink-users@xxxxxxxxxxx
                <mailto:eclipselink-users@xxxxxxxxxxx>>

https://dev.eclipse.org/mailman/listinfo/eclipselink-users

                   _______________________________________________
                   eclipselink-users mailing list
                   eclipselink-users@xxxxxxxxxxx
                <mailto:eclipselink-users@xxxxxxxxxxx>
                <mailto:eclipselink-users@xxxxxxxxxxx
                <mailto:eclipselink-users@xxxxxxxxxxx>>

https://dev.eclipse.org/mailman/listinfo/eclipselink-users



                ------------------------------------------------------------------------

                _______________________________________________
                eclipselink-users mailing list
                eclipselink-users@xxxxxxxxxxx
                <mailto:eclipselink-users@xxxxxxxxxxx>
                https://dev.eclipse.org/mailman/listinfo/eclipselink-users

            _______________________________________________
            eclipselink-users mailing list
            eclipselink-users@xxxxxxxxxxx
            <mailto:eclipselink-users@xxxxxxxxxxx>
            https://dev.eclipse.org/mailman/listinfo/eclipselink-users





------------------------------------------------------------------------

_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top