-->
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.  [ 3 posts ] 
Author Message
 Post subject: @SqlResultSetMapping, @FieldResult, and dotted notation
PostPosted: Fri Jan 02, 2009 4:41 pm 
Newbie

Joined: Fri Jan 02, 2009 4:26 pm
Posts: 5
I have a native query that uses a @SqlResultSetMapping to map to an object. Here is a snippet of the class w/ the mapping:

Code:
@SqlResultSetMapping(name = "logResultSetMapping",
    entities = @EntityResult(
        entityClass = ClientInstanceLog.class,
        fields = {
            @FieldResult(name = "clientInstanceLogId", column = "clientinstancelogid"),
            @FieldResult(name = "clientInstance.clientInstanceId", column = "clientinstanceid"),
            @FieldResult(name = "actionsObtainedDate", column = "actionsobtaineddate"),
            @FieldResult(name = "ipAddress", column = "ipaddress")
        })
)
public class ClientInstanceLog implements Serializable {

    private static final long serialVersionUID = 1L;
   
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ClientInstanceLogId", unique = true, nullable = false)
    private long clientInstanceLogId;
   
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "ClientInstanceId", nullable = false)
    private ClientInstance clientInstance;

    ...


And here is a snippet of that ManyToOne class:

Code:
public class ClientInstance implements Serializable {

    private static final long serialVersionUID = 1L;
   
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ClientInstanceId", unique = true, nullable = false)
    private long clientInstanceId;

    ...


2.3.2 of the Hibernate Annotations manual has an example using dotted notation that does this. However (regardless of whether I place referencedColumnName in the @JoinColumn annotation), I get the following error on startup (some hibernate debug logs included):

Code:
...some debug info...
14:34:23,597 DEBUG org.hibernate.cfg.CollectionSecondPass - Mapped collection key: ClientInstanceId, one-to-many: com.yieldstar.rms.bridge.model.ClientInstanceLog
14:34:23,597 DEBUG org.hibernate.cfg.Configuration - processing native query and ResultSetMapping mappings
14:34:23,597  INFO org.hibernate.cfg.annotations.ResultsetMappingSecondPass - Binding resultset mapping: logResultSetMapping
...error...
Caused by: org.hibernate.MappingException: dotted notation reference neither a component nor a many/one to one
        at org.hibernate.cfg.annotations.ResultsetMappingSecondPass.getSubPropertyIterator(ResultsetMappingSecondPass.java:210)
        at org.hibernate.cfg.annotations.ResultsetMappingSecondPass.doSecondPass(ResultsetMappingSecondPass.java:86)
        at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1145)
        at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:324)
        at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1121)
        at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:673)
        at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1368)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1334)
        ... 52 more
Caused by: java.lang.ClassCastException: org.hibernate.mapping.SimpleValue cannot be cast to org.hibernate.mapping.Component
        at org.hibernate.cfg.annotations.ResultsetMappingSecondPass.getSubPropertyIterator(ResultsetMappingSecondPass.java:202)
        ... 60 more


Granted, I am using Spring. Am I doing something wrong here? Is this a Spring specific issue?

Thanks in advance.


Top
 Profile  
 
 Post subject: Re: @SqlResultSetMapping, @FieldResult, and dotted notation
PostPosted: Sat May 30, 2009 2:23 am 
Newbie

Joined: Sat May 30, 2009 2:09 am
Posts: 1
I'm getting the same exception for the annotation below
Code:
@SqlResultSetMapping(name = "fullTextIndexQuery",
      entities = @javax.persistence.EntityResult(entityClass = MediaItem.class,
   fields = {
      @FieldResult(name = "mediaItemKey", column = "mediaItemKey"),
      @FieldResult(name = "contentProvider.contentProviderKey", column = "contentProviderKey"),      
      }

      ), columns = {})

public class MediaItem {
   private long mediaItemKey;
   private ContentProvider contentProvider;

       @ManyToOne(optional = false, fetch = FetchType.LAZY)
   @JoinColumn(name = "contentProviderKey", unique = false, nullable = false)
   @ForeignKey(name = "CMS_MediaItems_FK2")
   public ContentProvider getContentProvider() {
      return this.contentProvider;
   }

   public void setContentProvider(ContentProvider cp) {
      this.contentProvider = cp;
   }
}


org.hibernate.MappingException: dotted notation reference neither a component nor a many/one to one
at org.hibernate.cfg.annotations.ResultsetMappingSecondPass.getSubPropertyIterator(ResultsetMappingSecondPass.java:210)
....
Caused by: java.lang.ClassCastException: org.hibernate.mapping.SimpleValue cannot be cast to org.hibernate.mapping.Component
at org.hibernate.cfg.annotations.ResultsetMappingSecondPass.getSubPropertyIterator(ResultsetMappingSecondPass.java:202)
... 27 more


Using Hibernate 3.3.1 with Annotations 3.4.0


Top
 Profile  
 
 Post subject: Re: @SqlResultSetMapping, @FieldResult, and dotted notation
PostPosted: Wed Aug 10, 2011 4:11 am 
Beginner
Beginner

Joined: Sat Nov 07, 2009 10:31 am
Posts: 22
I too have same problem . could you please some answer this.

thanks In Advance

_________________
Jana


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