Injecting org.hibernate.Session

27 views
Skip to first unread message

Fayder Florez

unread,
Nov 24, 2009, 10:10:33 AM11/24/09
to Tapestry-OSGi
Hello!

In the Apache Tapestry site they suggest to inject the
org.hibernate.Session object to interact with the database.

@Inject
private Session session;

public List<Address> getAddresses()
{
return session.createCriteria(Address.class).list();
}

If i try to do the same in a project using tapestry-osgi plugin, this
session object will be null. What would be the alternative for this in
tapestry-osgi projects?

Thanks

Fayder
Intern
Zero OÜ

Fayder Florez

unread,
Nov 30, 2009, 7:19:51 AM11/30/09
to Tapestry-OSGi
Is it possible to have another org.extwind.tapestry bundle where the
following method:

/**
* Overridden in subclasses to provide additional module definitions
beyond
* those normally located. This implementation returns an empty
array.
*/
protected ModuleDef[] provideExtraModuleDefs(ServletContext context)
{
return new ModuleDef[0];
}

In ProxyTapestryFilter.java is replaced by smth like

/**
* Overridden in subclasses to provide additional module definitions
beyond
* those normally located. This implementation returns an empty
array.
*/
protected ModuleDef[] provideExtraModuleDefs(ServletContext context)
{
return new ModuleDef[] {
new SpringModuleDef(context)
};
}

In order to be able to have smth like the TapestrySpringFilter???

Fayder Florez

unread,
Dec 15, 2009, 3:48:21 AM12/15/09
to Tapestry-OSGi
I know Tapestry-OSGi is not compatible with Spring IoC, but as I was
having problems using Tapestry-OSGi IoC to use Hibernate, I posted
this doubts.

What I finally did was to configure a Session Factory programmatically
in my DAO object. Smth like this:

<code>
AnnotationConfiguration cfg = new AnnotationConfiguration();
SessionFactory sf = cfg.configure("/config/
hibernate.cfg.xml").buildSessionFactory();
Session session = sf.openSession();
etc...
</code>

Fayder
Intern
ZERO TECHNOLOGIES OÜ

donf yang

unread,
Dec 15, 2009, 4:16:44 AM12/15/09
to tapest...@googlegroups.com
You can try to create a Interface named "MySessionFactory",
 
public interface MySessionFactory{
    public Session createSession();
}
 
public class MySessionFactoryImpl implements MySessionFactory{
    private SessionFactory sf ;
 
    public void init(){
        AnnotationConfiguration cfg = new AnnotationConfiguration();
        sf = cfg.configure("/config/hibernate.cfg.xml").buildSessionFactory();
    }
 
    public Session createSession(){
         return sf.openSession();
    }
}
 
and build it as a Tapestry service in your module.class like this:
 
public static MySessionFactory buildMySessionFactory(){
    MySessionFactoryImpl service = new MySessionFactoryImpl();
    service.init();
    return service;
}
 
 
2009/12/15 Fayder Florez <fayder...@gmail.com>
 
--
 
You received this message because you are subscribed to the Google Groups "Tapestry-OSGi" group.
To post to this group, send email to tapest...@googlegroups.com.
To unsubscribe from this group, send email to tapestry-osg...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/tapestry-osgi?hl=en.
 
 
 
 
 
--
 
Regards,
 
Donf Yang
------------------------------------------------------------------------------
To be surprised,to wonder,is to begin to understand.
 
Reply all
Reply to author
Forward
0 new messages