-->
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.  [ 7 posts ] 
Author Message
 Post subject: could not determine type for: java.util.List
PostPosted: Mon Oct 09, 2006 8:04 am 
Newbie

Joined: Wed Jul 13, 2005 5:36 am
Posts: 7
Hello,

I'm trying to get a Petclinic example to run on the latest HEM release (I works fine on Toplink Essentials and OpenJPA snapshot). However, I get a Could not determine type exception ...
I'm not using any annotations - I rely only on XML.

Hibernate version:
3.2CR5/ HEM 3.2CR2 / HA 3.2CR2
Mapping documents:
Code:
<mapped-superclass class="BaseEntity">
        <attributes>
            <id name="id">
                <generated-value strategy="IDENTITY"/>
            </id>
        </attributes>
    </mapped-superclass>
   
    <mapped-superclass class="NamedEntity">
        <attributes>
            <basic name="name">
                <column name="NAME"/>
            </basic>
        </attributes>
    </mapped-superclass>

   <mapped-superclass class="Person">
      <attributes>
      <basic name="firstName">
             <column name="FIRST_NAME"/>
        </basic>
        <basic name="lastName">
             <column name="LAST_NAME"/>
        </basic>
      </attributes>       
   </mapped-superclass>
    <!--=================-->
    <!-- Entity mappings -->
    <!--=================-->

    <entity class="Vet">
        <table name="VETS"/>
        <attributes>

            <many-to-many name="specialtiesInternal" target-entity="Specialty" fetch="EAGER">
                <join-table name="VET_SPECIALTIES">
                    <join-column name="VET_ID"/>
                    <inverse-join-column name="SPECIALTY_ID"/>
                </join-table>
            </many-to-many>
        </attributes>
    </entity>

    <entity class="Specialty">
        <table name="SPECIALTIES"/>
    </entity>

    <entity class="Owner">
        <table name="OWNERS"/>
        <attributes>

            <one-to-many name="petsInternal" target-entity="Pet" mapped-by="owner" fetch="EAGER">
                <cascade><cascade-all/></cascade>
            </one-to-many>
        </attributes>
    </entity>

    <entity class="Pet">
        <table name="PETS"/>
        <attributes>
            <basic name="birthDate">
                <column name="BIRTH_DATE"/>
                <temporal>DATE</temporal>
            </basic>
            <many-to-one name="owner" fetch="EAGER">
                <cascade><cascade-merge/></cascade>               
            </many-to-one>           
            <many-to-one name="type" fetch="EAGER"/>

  <!-- problem occurs here -->

            <one-to-many name="visitsInternal" target-entity="Visit" mapped-by="pet" fetch="EAGER">
                <cascade><cascade-all/></cascade>
            </one-to-many>
        </attributes>
    </entity>

    <entity class="PetType">
        <table name="TYPES"/>
    </entity>

    <entity class="Visit">
        <table name="VISITS"/>
        <attributes>
            <basic name="date">
                <column name="VISIT_DATE"/>
                <temporal>DATE</temporal>
            </basic>
            <many-to-one name="pet" fetch="EAGER">
                <cascade><cascade-merge/></cascade>               
            </many-to-one>           
        </attributes>
    </entity>

</entity-mappings>


Full stack trace of any exception that occurs:
Code:
Caused by: org.hibernate.MappingException: Could not determine type for: java.util.List, for columns: [org.hibernate.mapping.Column(visits)]
   at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:266)
   at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253)
   at org.hibernate.mapping.Property.isValid(Property.java:185)
   at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:410)
   at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
   at org.hibernate.cfg.Configuration.validate(Configuration.java:1026)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1211)
   at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:688)
   ... 49 more

Name and version of the database you are using:
hsqldb 1.8.0.1


Thanks for the help!
--
Costin

_________________
--
Costin


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 09, 2006 5:39 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
hi,
Do you have a property or a column named "visits" somewhere? in your object model? I can't see it in the XML file
You might be missing metadata-complete="true"

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 09, 2006 6:03 pm 
Newbie

Joined: Wed Jul 13, 2005 5:36 am
Posts: 7
Hi Emanuel.

I didn't attach the header of the orm.xml file as I though it wasn't relevant (see it below). The file does contain the <xml-mapping-metadata-complete/> tag.
Code:
    <persistence-unit-metadata>
        <xml-mapping-metadata-complete/>
        <persistence-unit-defaults>
            <access>PROPERTY</access>
        </persistence-unit-defaults>
    </persistence-unit-metadata>



As for the mapping, the Vet class wraps the mapped visit with some getter/setter methods which provide some application logic. I've posted the class below (the code it's let's say legacy so heavy modifications to it are not allowed at the moment):

Code:
public class Pet extends NamedEntity {
   private Owner owner;

   private Set visits;

   protected void setVisitsInternal(Set visits) {
      this.visits = visits;
   }

   protected Set getVisitsInternal() {
      if (this.visits == null) {
         this.visits = new HashSet();
      }
      return this.visits;
   }

   public List getVisits() {
      List sortedVisits = new ArrayList(getVisitsInternal());
      PropertyComparator.sort(sortedVisits, new MutableSortDefinition("date", false, false));
      return Collections.unmodifiableList(sortedVisits);
   }

   public void addVisit(Visit visit) {
      getVisitsInternal().add(visit);
      visit.setPet(this);
   }

}


As you can see the internal visit set gets translated into a list. However, the getVisits() is used only inside the application (that's why there is no setter for it). However, the getter/setter for internalVisits are in place (and with the correct type).

By the look of the exception, seems that the wrong property getVisits is being picked up (not sure why).
Thanks for your help![/code]

_________________
--
Costin


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 09, 2006 7:02 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
My understanding of the spec is that JPA XML is supposed to mimmic annotation use.
This is the way Hibernate Annotations is done, so you'll need to add a @Transient annotation on non persistent property

In you case

Code:
<entity class="Pet">
        <table name="PETS"/>
        <attributes>
            <basic name="birthDate">
                <column name="BIRTH_DATE"/>
                <temporal>DATE</temporal>
            </basic>
            <many-to-one name="owner" fetch="EAGER">
                <cascade><cascade-merge/></cascade>               
            </many-to-one>           
            <many-to-one name="type" fetch="EAGER"/>

  <!-- problem occurs here -->

            <one-to-many name="visitsInternal" target-entity="Visit" mapped-by="pet" fetch="EAGER">
                <cascade><cascade-all/></cascade>
            </one-to-many>
            [b]<transient name="visits"/>[/b]
        </attributes>
    </entity>

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 10, 2006 2:33 am 
Newbie

Joined: Wed Jul 13, 2005 5:36 am
Posts: 7
Thanks Emmanuel! Using transient solved my problem.

Cheers!

_________________
--
Costin


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2009 9:07 am 
Newbie

Joined: Wed Dec 17, 2008 2:37 am
Posts: 4
Hi..

I am facing same problem but in my case its a list of enums and I want to persist it. How do I do that?

I am using Spring and Annotations


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 12, 2009 9:08 am 
Beginner
Beginner

Joined: Fri Nov 14, 2008 7:11 am
Posts: 31
Bajiquan wrote:
Hi..

I am facing same problem but in my case its a list of enums and I want to persist it. How do I do that?

I am using Spring and Annotations


Use the @CollectionOfElements Annotation like

Code:
public enum DeviceType {
...}

...
public class MyEntity
{
...
   @CollectionOfElements
   public Set<DeviceType> getDeviceTypes() {
      return deviceTypes;
   }


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