Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Custom SQL for relationship

Well, you have several issues: I usually use a simple native sql-query calling a procedure or function, e.g.
CREATE OR REPLACE FUNCTION "public"."fx_hello_world" (IN int4, IN int4) RETURNS bool AS
$BODY$
BEGIN
	IF $1 = 1 THEN
		RETURN TRUE;
	ELSE
		RETURN FALSE;
	END IF;
END
$BODY$
Invocation:
SELECT * FROM fx_hello_world(1,1);
SELECT fx_hello_world(1,1);
In Java (in your EJB)
@PersistenceContext(name="myJTA")
private EntityManager em;

//defined in remote interface
@Override
public Company getDefaultCompany(){
    Query q = em.createQuery("SELECT * FROM mystoredprocedure");
    return q.getResultList().get(0);
}
I don't know why you can't inject your EJB. You should provide a little more information and error logs (remote or local lookup, application server, etc.) Maybe for this issue you should make another post corresponding to the application server mailing list. Hope this helps.
Bálint Kriván wrote:
Hi! Thanks for your reply! I would like to have the getDefaultCompany() method, but I can't code it in the entity bean, that's why I'm asking, if there is a way to query the DB (call the procedure or execute arbitrary queries) from the Entity bean (I can't inject stateless EJB for some reason -> i'm getting null for the injected bean -- What am I doing wrong?).


View this message in context: Re: Custom SQL for relationship
Sent from the EclipseLink - Users mailing list archive at Nabble.com.

Back to the top