-->
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: Help - Stored Procedure and Annotations?
PostPosted: Mon Aug 18, 2008 11:06 am 
Newbie

Joined: Mon Aug 18, 2008 10:54 am
Posts: 11
Location: Devon, UK
I am trying a very simple use of Hibernate Annotations to call a Stored Procedure which is in Oracle 10gR2.
I am not using EJB or JavaEE, this is simple standard Java. I have annotated my class, however and created the mapping in hibernate.cfg.xml. I know the config file is being read, however when I call getNamedQuery() it always says that it cant find the query, what am I doing wrong?

I have done a lot of googling but havent yet found a solid example of using Hibernate Annotations with Stored Procedures, perhaps someone here knows how?

Hibernate version: 3.3.0.CR2
Hibernate Annotations version: 3.4.0.CR2

Config document:
<hibernate-configuration>
<session-factory>
<!-- database connection details -->
<property name="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@123.123.123.123:1521:EXHCDEV1</property>
<property name="hibernate.connection.username">username</property>
<property name="hibernate.connection.password">password</property>

<mapping class="uk.co.landmarkinfo.www.addressmatchportal.source.internal.register.EWDomestic"/>

</session-factory>
</hibernate-configuration>

Main Code:
AnnotationConfiguration config = new AnnotationConfiguration();
SessionFactory sessionFactory = config.configure().buildSessionFactory();
Session session = sessionFactory.openSession();
Query q = session.getNamedQuery("sa");

Annotated Class:
import org.hibernate.annotations.Entity;
import org.hibernate.annotations.NamedNativeQuery;

@Entity
@NamedNativeQuery(
name = "sa",
callable = true,
query = "call hcr_address_query.search_addresses(:addressKey, :oragnisationId, :deliveryPointId)",
readOnly = true,
cacheable = true
)
public class EWDomestic
{
private String unique_property_ref_no;
private String addr_line_1;
private String addr_line_2;
private String addr_line_3;
private String post_town;
private String post_code;
private String manual_ind;

public EWDomestic()
{
}
}

Full stack trace of any exception that occurs:
Exception in thread "main" org.hibernate.MappingException: Named query not known: sa
at org.hibernate.impl.AbstractSessionImpl.getNamedQuery(AbstractSessionImpl.java:70)
at org.hibernate.impl.SessionImpl.getNamedQuery(Sess
ionImpl.java:1260)
at uk.co.landmarkinfo.www.addressmatchportal.source.internal.register.HibernateTest.someMethod(HibernateTest.java:26)
at uk.co.landmarkinfo.www.addressmatchportal.source.internal.register.HibernateTest.main(HibernateTest.java:16)
Java Result: 1

Name and version of the database you are using:
Oracle 10gR2



Thanks Adam.

_________________
Adam Retter


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 20, 2008 6:34 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

I don't think that the annotations on EWDomestic are actually picked up. Check the log. If they would be picked up you would also get an exception because @Id is mandatory.

Since you create the AnnotationConfiguration yourself I think you are missing:
Code:
config.addAnnotatedClass(EWDomestic.class);


Hope this helps.

--hardy


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 04, 2008 7:30 am 
Newbie

Joined: Fri Aug 01, 2008 8:27 am
Posts: 1
Hi

In the following decleration you need to mention the class name (EWDomestic ) also.
You should declare it in the following way


@Entity
@NamedNativeQuery(
name = "sa",
callable = true,
query = "call hcr_address_query.search_addresses(:addressKey, :oragnisationId, :deliveryPointId)",
readOnly = true,
cacheable = true
resultClass=EWDomestic .class)

_________________
Regards,
Srisilpa K


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.