Fóruns

Início » Liferay Portal » English » 3. Development

Visualização combinada Visão plana Exibição em árvore
Tópicos [ Anterior | Próximo ]
toggle
Dhandapani S
Need sample Hibernate+Spring Portlet with DB interaction
1 de Agosto de 2012 23:44
Resposta

Dhandapani S

Ranking: Regular Member

Mensagens: 170

Data de entrada: 24 de Março de 2009

Mensagens recentes

Hi All,

I need to develop sample portlet with db interaction using hibernate+Spring. If any one have sample war file, please share.

Thanks in advance.

Regards
Dhans006
David H Nebinger
RE: Need sample Hibernate+Spring Portlet with DB interaction
2 de Agosto de 2012 06:25
Resposta

David H Nebinger

Community Moderator

Ranking: Liferay Legend

Mensagens: 11295

Data de entrada: 1 de Setembro de 2006

Mensagens recentes

You have a bunch of examples already, all based on ServiceBuilder. Anything service builder based uses hibernate and spring.
Hitoshi Ozawa
RE: Need sample Hibernate+Spring Portlet with DB interaction
2 de Agosto de 2012 15:28
Resposta

Hitoshi Ozawa

Ranking: Liferay Legend

Mensagens: 7949

Data de entrada: 23 de Março de 2010

Mensagens recentes

As David replied, liferay is using Spring + Hibernate under the covers.

You can go through tutorial in Development to create a sample portlet.
http://www.liferay.com/documentation/liferay-portal/6.1/development/-/ai/service-build-5
Vishal Panchal
RE: Need sample Hibernate+Spring Portlet with DB interaction
3 de Agosto de 2012 03:27
Resposta

Vishal Panchal

Ranking: Expert

Mensagens: 279

Data de entrada: 20 de Maio de 2012

Mensagens recentes

Hi Dhandapani S,

As I seen your post I decide to make sample portlet with db interaction using hibernate+Spring.

And I did it..!!

.war file is attached below..

Please let me know if any inputs require.

Thanks & Regards,
Vishal R. Panchal
Anexos: Spring-Hibernate-Demo-portlet-6.0.10.1.war (11.496,4k)
David H Nebinger
RE: Need sample Hibernate+Spring Portlet with DB interaction
3 de Agosto de 2012 05:18
Resposta

David H Nebinger

Community Moderator

Ranking: Liferay Legend

Mensagens: 11295

Data de entrada: 1 de Setembro de 2006

Mensagens recentes

Vishal, it's not that it can't be done (I've done it a number of times myself), it's that it shouldn't be done...

The problem with this approach comes in when other plugins need the same entities.

You have two choices:

1. copy the mapping file(s) and implementation classes to the new plugin.
2. put all of the plugins that need access into the same war file.

The problem with #1 is that you're copying code around. You must manage the synchronization of code changes out and about and hopefully you'd eventually figure out a way to do it. The bigger problem is that you increase your resource consumption without being aware of it... If you add the classes to another plugin, the other plugin will need a database connection for the hibernate stuff, so you have (at least) 2 db connections used for this (probably more because you don't want to choke the code because of no DB connection). As you add more plugins and copy the code around, these same resource requirement increases also get copied.

Now step #2 solves that problem, although it too gets to be ugly. If you have all of your plugins in a single plugin, pretty soon that plugin is going to be difficult to manage. Then there's the whole deployment issue (I only changed one file in this portlet, but since it's in one war we now have to test all of them, etc.).

Then there's the Liferay way. The liferay way has you using Service Builder. You create a plugin, put your service.xml in there and generate all of the code. You add methods to the XxxLocalServiceImpl classes to flush out your API, but in the end you've got a fine layer for local (and possibly remote) data access usage. You can create other completely separate plugins, but rather than getting copies of all of the code, you get a thin service jar which is the shim to the shared service implementation.

In Liferay it's definitely the way to go.
Vishal Panchal
RE: Need sample Hibernate+Spring Portlet with DB interaction
3 de Agosto de 2012 05:36
Resposta

Vishal Panchal

Ranking: Expert

Mensagens: 279

Data de entrada: 20 de Maio de 2012

Mensagens recentes

Hi David H Nebinger,

I got the whole issue.
Thank you for the explanation your time and consideration.
I will never use these approach as it has many drawbacks as emoticon resource consumption , number of db connection and finally repeating the code (service method) as number of plugins increase to use the same.

But one question , Is there any way through we can make JAR file of our service classes which can be shared by multiple plugins locally / remotely.?


Thanks & Regards,
Vishal R. Panchal
David H Nebinger
RE: Need sample Hibernate+Spring Portlet with DB interaction
3 de Agosto de 2012 06:01
Resposta

David H Nebinger

Community Moderator

Ranking: Liferay Legend

Mensagens: 11295

Data de entrada: 1 de Setembro de 2006

Mensagens recentes

You automatically get that. When you run SB, in the WEB-INF/lib folder you'll find the service jar.

You have two options to share it:

1) the old way, deploy your plugin, shut down the app server, move the service jar from the deployed war's WEB-INF/lib directory to the application server's global lib dir (i.e. lib/ext in tomcat), then start the server. All plugins will have visibility to the service jar and can call the methods directly.

2) the new way, for each plugin that will be using the service, add the plugin providing the service as a required deployment context in liferay-plugin-package.properties. The IDE will copy the service jar in for you, so you don't have to do any of the stuff in #1. It does have it's own quirks, of course (as a compile-time thing of the IDE, it is possible to have different versions of the service jar floating around if you don't deploy all consumers when you deploy the provider).
Vishal Panchal
RE: Need sample Hibernate+Spring Portlet with DB interaction
3 de Agosto de 2012 06:08
Resposta

Vishal Panchal

Ranking: Expert

Mensagens: 279

Data de entrada: 20 de Maio de 2012

Mensagens recentes

Sir,

That one I got but what I was thinking that "If we follow my approach than Is there any way through we can make JAR file of our service classes which can be shared by multiple plugins locally / remotely.? "

So I mean in Spring+hibernate portlet can we make a jar file of service classes (as same as service builder) which can be shared across multiple plugins instead of coping the classes to each plugin (or put all plugins in same .war file) ..?



Thanks & Regards,
Vishal R. Panchal
David H Nebinger
RE: Need sample Hibernate+Spring Portlet with DB interaction
3 de Agosto de 2012 06:23
Resposta

David H Nebinger

Community Moderator

Ranking: Liferay Legend

Mensagens: 11295

Data de entrada: 1 de Setembro de 2006

Mensagens recentes

The magic of SB is that it creates a shim level to cross the class loader boundary between web applications. When you look inside a SB-based service jar, you see a lot of classes with Clp on the end, these are the class loader proxies.

When you create an instance of a class in one web app there are typically a lot of things that you have to worry about when accessing that class in another web app because of the class loader boundary.

Sure, you could eventually emulate all of the learned knowledge and experience built into SB code. But the question is, why would you want to?
Vishal Panchal
RE: Need sample Hibernate+Spring Portlet with DB interaction
3 de Agosto de 2012 06:29
Resposta

Vishal Panchal

Ranking: Expert

Mensagens: 279

Data de entrada: 20 de Maio de 2012

Mensagens recentes

Sir,

Thanks for the deep explanation.

Finally I will use SB which has a great magic and will not try to emulate the same emoticon.

Thank You..!!

Thanks & Regards,
Vishal R. Panchal
sravan kumar
RE: Need sample Hibernate+Spring Portlet with DB interaction
18 de Junho de 2014 03:13
Resposta

sravan kumar

Ranking: Junior Member

Mensagens: 78

Data de entrada: 19 de Fevereiro de 2013

Mensagens recentes

Hi,

I created a project a based on war file, it it showing @BeanReference can not found exception,(classNOtFoundException)


let me know if any jar files i need to include.
Meera Prince
RE: Need sample Hibernate+Spring Portlet with DB interaction
18 de Junho de 2014 05:22
Resposta

Meera Prince

Ranking: Liferay Legend

Mensagens: 1110

Data de entrada: 8 de Fevereiro de 2011

Mensagens recentes

Hi

The following is liferay spring hibernate portlet it may help you..

http://www.liferaysavvy.com/2013/12/liferay-spring-portlet.html

Regards,
Meera Prince
Pavan B Modi
RE: Need sample Hibernate+Spring Portlet with DB interaction
28 de Agosto de 2014 23:00
Resposta

Pavan B Modi

Ranking: New Member

Mensagens: 2

Data de entrada: 28 de Agosto de 2014

Mensagens recentes

Hi Vishal,

I need you assistance for following issue.

https://www.liferay.com/community/forums/-/message_boards/message/42040102

Please take a look in post.