I'm just writing a small java application and I would like to be able to persist the data model in a database. So I was wondering if I could use JPA for this. I used JPA some time ago, but as far as I remembered it required an application server. So I'm wondering can I just JPA to pe开发者_开发问答rsists my classes w/o using an application server.
Yes, you can use JPA without an application server. Here's a tutorial which may help you: TopLink JPA: How to use JPA with Java SE
Yes, you can use JPA
without any application server. Look at section 2.4 in this tutorial for Hibernate.
JPA is, umm, "traditionally" associated with application servers because JPA is part of the Java EE spec. However, that doesn't mean individual implementations of JPA can't work outside of an app server.
I've personally done this with Hibernate, which is perhaps the most popular JPA implementation. The Hibernate documentation gives you some tips about how to run Hibernate in a standalone application.
You're probably better off using Hibernate standalone; it's a bit easier to manage without the extra JPA layer on top. There isn't that much difference anyway.
No J2EE server present in this tutorial http://www.datanucleus.org/products/accessplatform/guides/jpa/tutorial.html
精彩评论