Newbie question on Java Persistence API - Entity Beans

Hi All,
I am basically new to Entities and the Java Persistence API. My question is, when using a container managed EntityManager, do I have to manually tidy-up any resources? Say for example, do I have to explicitly close the database connection (if ever I have that ability)? Invoke close() on EntityManager?
- Pat

You don't have to. That's what they mean by container managed. The container does it for you.
In fact you will get an IllegalStateException if you call close on a container-managed EntityManager.

Similar Messages

  • Question about Java Persistence API.

    is Java Persistence API a Object-Relational Mapping Framework, or the java Programmer can use this API to do mapping between Java Applicatiion and Relational Database ??

    http://java.sun.com/javaee/overview/faq/persistence.jsp

  • Java Persistence API and creation of databases

    Hi All
    I have designed a small address book application which uses a database to store the information. I have used the new Java Persistence API to take care of my transactions and querrys with the database. This works great for one set database which is generated the first time the application runs and is used all the time.
    However I would like to make it so that the user can create a new address book (database) with a different name, I am not sure how I would do this using the Java Persistence API. I know the persistence.xml file must be placed in the META-INF directory of the source, so how would I be able manipulate the file or could I place the file somewhere else.
    David

    I am using the Derby database. I can create a database by passing the create command when I create the entity Manager like so:
    Connection c = DriverManager.getConnection("jdbc:derby:AddressBook;create=true", "app", "app");My problem is that as I understand it the persistence.xml file must know the name of the database. Unless there is another way of setting this. The line in the persistence file I am referring to is:
    <property name="toplink.jdbc.url" value="jdbc:derby:AddressBook"/>I wonder if I can progamatically set this value so that I have a default database in the persistence.xml and others can then create there own.
    David

  • DAO pattern and Java Persistence API

    Hi
    This is a question for anyone who might be familiar with the standard DAO design pattern and the Java Persistence API (JPA - part of EJB3). I'm new to this technology, so apologies for any terminology aberrations.
    I am developing the overall architecture for an enterprise system. I intend to use the DAO pattern as the conceptual basis for all data access - this data will reside in a number of forms (e.g. RDBMS, flat file). In the specific case of the RDBMS, I intend to use JPA. My understanding of JPA is that it does/can support the DAO concept, but I'm struggling to get my head around how the two ideas (can be made to) relate to each other.
    For example, the DAO pattern is all about how business objects, data access objects, data transfer objects, data sources, etc relate to each other; JPA is all about entities and persistence units/contexts relate to each other. Further, JPA uses ORM, which is not a DAO concept.
    So, to summarise - can DAO and JPA work together and if so how?
    Thanks
    P.S. Please let me know if you think this topic would be more visible in another forum (e.g. EJB).

    Thanks, duffymo, that makes sense. However ... having read through numerous threads in which you voice your opinion of the DAO World According to Sun, I'd be interested to know your thoughts on the following ...
    Basically, I'm in the process of proposing an enterprise system architecture, which will use DAO as the primary persistence abstraction, and DAO + JPA in the particular case of persistence to a RDBMS. In doing so, I'd like to illustrate the various elements of the DAO pattern, a la the standard class diagram that relates BusinessObject / DataAccessObject / DataSource / TransferObject (http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html). With reference to this model, I know that you have a view on the concept of TransferObject (aka ValueObject?) - how would you depict the DAO pattern in its most generic form? Or is the concept of a generic DAO pattern compromised by the specific implementation that is used (in this case JPA)?

  • Java persistence api : ejb ql

    Hi,
    I am using java persistence api(over oracle toplinks)
    I have an entity customer and another entity contacts.
    customer is mapped with contact as one to many.
    the contact have a field primarycontact.
    I want to get the contact name from contacts for a customer where primarycontact field is true. and set this contact name as a field customercontact which is a string in customer..
    I got a way by executing multiple queries.
    but is it possible to do this in single query using ejb ql?
    Any help will be greatly appreciated..
    Thanks in advance....

    @Id
    @GeneratedValue( @GeneratedValue(strategy= GenerationType.TABLE, generator="SOMENAME")
    public int setId() {
    returrn this.id;
    in the database you need to create table using following commands
    CREATE TABLE SEQUENCE
    SEQ_NAME VARCHAR(50),
    SEQ_COUNT DECIMAL(15)
    and insert a row initally with the same "SOMENAME" like
    insert into sequence values ( "SOMENAME", 1);
    you can get the next id by adding 50(default) to "SELECT SEQ_COUNT FROM SEQUENCE WHERE SEQ_NAME = "SOMENAME"
    hope this provides a solution.

  • Java persistence API

    Hi! I am trying to learn to use the http://www.devx.com/Java/Article/33650/ api manually, i tried using netbeans 6.0 for it but i'm not very sure what it does so i am going to try it manually now. I've read these 2 articles by Antonio Goncalves
    (http://www.devx.com/Java/Article/33650/ && http://www.devx.com/Java/Article/33906/) it doesn't look very difficult at first but the thing is in netbeans 6.0 when i try to use the annotations,@Inheritance for example, It autocompletes but i don't see the javadoc it says ("Javadoc not found"). I already added the javaee5 documentation to the javaplataform manager but it doesn't do the trick.
    Anybody can help? Also if you know any kind of tutorial for the persistence api if you could point me towards there it would be nice.
    And finally sorry if i have misplaced this post, I couldn't find a better place.
    Thanks, Joaquin

    Hi! I am trying to learn to use the http://www.devx.com/Java/Article/33650/ api manually, i tried using netbeans 6.0 for it but i'm not very sure what it does so i am going to try it manually now. I've read these 2 articles by Antonio Goncalves
    (http://www.devx.com/Java/Article/33650/ && http://www.devx.com/Java/Article/33906/) it doesn't look very difficult at first but the thing is in netbeans 6.0 when i try to use the annotations,@Inheritance for example, It autocompletes but i don't see the javadoc it says ("Javadoc not found"). I already added the javaee5 documentation to the javaplataform manager but it doesn't do the trick.
    Anybody can help? Also if you know any kind of tutorial for the persistence api if you could point me towards there it would be nice.
    And finally sorry if i have misplaced this post, I couldn't find a better place.
    Thanks, Joaquin

  • Question about multiple RequiresNew in Entity Bean transaction

    Hi I've got a problem concerning transactions:
    In both cases I've got a CMP Entity Bean called "Account" with some mothods like
    increaseBalance(double amount)
    decreaseBalance(double amount)
    transferMoney(double amount)
    for all methods the TransactionAttribute is "RequiresNew". When calling first decreaseBalance(amount) and afterwords
    increaseBalance(amount), bothfrom within transferMoney(amount). When setting entityContext.RollbackOnly()
    I would expect this rollback doesn't undo my changes because they are in a different transaction, which has been comitted
    when the methods finished, but both are rolled back.
    I thought there are no "nested transactions" in J2EE. Isn't this one?
    Thanks!
    Martin

    Ahhhh! Right! If I call "this.increase(balance)" from the AccountBean method "transferMoney", the container has no chance to create a new transaction, so the same transaction as in "transferMoney" is used. I didn't think about that, but of course...
    So one should never call a bean method directly even when it is a method of the same instance the thread is currently in.
    Thanks a lot!

  • Newbie question: tapping native OS APIs through java?

    I'm new to java, and was wondering if classes existed for doing windows platform specific things on the windows platform. Please point me to any information/sites, or suggested search terms for a search engine.
    Things like if I wanted to edit a registry key, or stop/start a windows service, or perhaps log something to the eventlog. I realize & believe in the Java principal of abstracting the OS, but sometimes you want to touch the OS functionalities.
    Is the answer to use another language? I know I could write extend Java with C functions, but thats not practical each time you want to touch the OS -- so I'd just use another language.
    thanks!

    ok, mostly you would use [url http://java.sun.com/products/jdk/1.2/docs/guide/jni/]JNI (Java Native Interface) and C.
    Not for the faint hearted.
    However, you might not have to go this way.
    registry key
    The java.ava.util.prefs package will use the registry on windows systems, but you have limited control over the regestry, you could also use the
    Runtime.exec( "..." ) trick, with an app pre-written like Cygwins Regtool.
    stop/start a windows service
    Again you could write some native code, or use the Runtime.exec trick with [url http://www.sysinternals.com/ntw2k/freeware/psservice.shtml]PS Service
    perhaps log something to the eventlog
    I think the the java.util.logging package uses the native event log in windows, and I'm sure [url http://jakarta.apache.org/log4j/docs/index.html]Log4j can use it.
    I could write extend Java with C functions, but thats not practical each time you want to touch the OS
    Eeh? How else do you expect it to work?
    OK, I agree JNI is pants, and should be replaced with CNI.

  • Best way to combine Java Persistence API (JPA)  with Visual Web Pack (VWP)?

    I like the JPA/Hibernate development approach to create the database elements from JAVA classes.
    This way one gets rid of the need to keep JAVA code and the database in sync.
    However I have not yet found a good way on how to use JPA from the netbeans VWP.
    Note that I have found the tutorial on how to use the IDE with hibernate and it works without problems.
    However I think this tutorial does not really implement a good Model/View/Controller approach as it is done in the enterprise pack.
    Here you have a controller session bean that deals with all the persistence logic and that exposes properties through a DataModel to the application.
    There is no need to encapsulate logic in inherited classes of the ObjectListDataProvider.
    Maybe an example makes it more clear:
    If we stay with the hibernate tutorial that we have "Animals" and "Pavillion" entities.
    How would one efficiently design a "Table" component that shows a list of all Animals and their Pavillions.
    With the VWP approach it is quite clear: you create a RowSet with the inner/left join between Animals and Pavillions.
    But how would you do it with JPA?

    You said:
    "If we stay with the hibernate tutorial that we have "Animals" and "Pavillion" entities.
    How would one efficiently design a "Table" component that shows a list of all Animals and their Pavillions.
    With the VWP approach it is quite clear: you create a RowSet with the inner/left join between Animals and Pavillions.
    But how would you do it with JPA?"
    I have the exact same question. Have you found the answer on how to "join" entities and display them on visual web table component?

  • Newbie question on JAVA networking

    Hi,
    I'm newbie on JAVA networking. Can anyone guide me to do a task to :
    read the TCP/IP packets which are sent from a specific host to another host? I need to capture the packets and analyse the contents.
    thanks in advance,
    jackling

    Well I've search google for a low level TCP api, but I came up with absolutely no results. So I guess the only way would be to write your own native API (using C/C++) and call this through the Java Native Interface.

  • Object, Query and Java Persistence API

    Hello Java Programmers.
    Question to Object handling with Query results and evaluation.
    Example:
    one table with 3 Columns
    Tablename = ISO6933
    Column 1 = UID
    Column 2 = language name
    Column 3 = language long name
    data in database:
    C1 = 1
    C2 = "ger"
    C3 = "german"
    read the data from database with EntityManagerFactory and EntityManager
    Query query = em.createNativeQuery("SELECT * FROM ISO6933");Final to - Query (Persistence) to Choice (AWT)
    Search short code for example!
    query.setFirstResult(0); // first element -> possible?
    java.util.List queryList = query.getResultList();
    // warnings -> List is a raw type. References to generic type List<E> should be parameterized
    java.awt.List list = new List();
    list.add(queryList.toString()); // for one element in the result, for more elements for/next loop
    // = [1,ger,german]I do not want to use
    - StringTokenizer
    - String.split
    (Cast from java.util.List to java.awt.List = Type mismatch: cannot convert from List to List)
    for one elements from [1,ger,german]
    final to
    1
    ger
    german
    in the AWT List()

    no answer? = is an answer !
    the normal solution would be for example.
         Query query = em.createNativeQuery("SELECT * FROM ISO693_3"); // create query
              query.setFirstResult(0); // first element          
              Object[] objectList = query.getResultList().toArray();          
              // objectList[X] = UID,LANGUAGE_ID,LANGUAGE_NAME
              int intLength = objectList.length; // Length          
              StringTokenizer token; // parser
              String string = new String(); // temp
              for (int i1=0;i1<intLength;i1++)
                   string = objectList[i1].toString();
                   string = string.substring(1, string.length()-1);
                   token = new StringTokenizer(string, ",");
                   while (token.hasMoreElements())
                        list.add(token.nextToken().trim()); // the next element and clean string
              }I look for however a better solution!
    Best greetings

  • A question about Java Card API 2.2.1

    Hi,I am doing my first project on java card and I have the software installed(java_card_kit-2_2_1, OCF 1.2, j2sdk1.4.1).
    java_card_kit-2_2_1 include these package:
    java.lang
    java.io
    java.rmi
    javacard.framework
    javacard.security
    javacardx.crypto
    com.sun.javacard.impl
    com.sun.javacard.crypto
    My question is:
    How can I get the export files of the last two package:com.sun.javacard.impl and com.sun.javacard.crypto?
    I really need your help and please mail to me.My email is [email protected] you very much.

    Hi libin_hailang
    The last two packages are not part of the api.
    So, you only can use them on the Simulation.
    On a real card implementation you will not find these packages.
    This may be the reason for the not existing export files .
    But if you need them for other purpose you can create them with the converter.
    bye.

  • Newbie question to java web services....

    hi,
    I used to be a .net programmer for a few years, and am have done web services in .net.... (using IIS, of course)
    And i moved onto Java side recently - and am pretty new to tomcat / axis..etc..
    I looked at the netbeans ide tutorial, and it covered on how to create a web services and a client using the IDE - with that is with the sun app server. Since I want to stick with Tomcat (which is a servlet container, i believe), the compilation complained that the HelloWSImpl.java is not a servlet, and will not let me run the web app. I have tried the WSDP 2.0 tutorial as well, but I first got the FastSetsource.jar not found? Then I got some other classes not found..etc... so, until now - i still am not able to create a web service, and a cliet to talk back and forth.
    I have the following questions..
    1. I am confused that how come tomcat itself is already a webserver, why would people use it on top of apache http server, which is another web server?
    2. To create a web services, (I am thinking of the .net web services that i have done - that once you deploy it with IIS, and you browse to that service, if the function takes 2 parameter, there will be 2 textboxes waiting for you to put data to, then once you post - the xml response will come back...), does java allow front end interface automatically like that in .net? Or you have to code the JSP pages to include those textboxes yourself, and do a manual post to the web services address?
    3. Are there any book out there, explains how to use tomcat for webservices? I have looked thru some of the java books that talks about web services, they mainly explain what webservices are, what is xml..etc... and of course, they did talk about the differenct type of messaging format available. (JAX-RPC..etc..)
    4. In the java world - how do you use webservices? Is it the same way that i am familiar with? Like, that we have a front end gui, that it will call the web services, pass it a few param, and get the xml result back, and parse it and display / store.. it? Or that is not the correct way to consume the web services in java world?
    5. In .net - as long as i have the .net framework sdk, and a IIS - i am good to go. In java - what do i need in order to deploy a web services?? I already have tomcat / jdk / wsdp / IDE - do i have enough to create a simple ws? if so, can you show me a basic tutorial??
    based on some reading, i understand that the ws on the service side, needs an SEI implementing java.rmi.remote, and we need another class implementing this SEI. But I would really want to see more example, or downloads, where i can just download / view the whole thing all at once... I googled "java web service", "jax-rpc example"..etc.. most of the return links are from either java.sun.com, or ibm, or some other vendor's web site, explaining the architecture... I really want to look at the code, to get a better understand, what is the relationship between each of these softwares (tomcat, apache http server, axis...)
    Any suggestions??
    Thanks,
    T

    I think I can answer your Q1
    Apache is very good at serving simple HTML pages
    Tomcat is capable of serving active content
    So the two complement each other
    Or that's how I understand it.
    Steaker

  • JPA, java persistence Api, troubleshooting

    Hi everybody.
    I have a small but boring problem.
    I am new at Netbeans and Java Sdk.
    I downloaded Netbeans 6.1 and SDK 6.
    I tried to exercise "simple database application" in the netbeans web page.
    A error encountered that:
    24.Tem.2008 10:04:16 org.jdesktop.application.Application$1 run
    SEVERE: Application class simpleAp.simpleAp failed to launch
    *javax.persistence.PersistenceException: No Persistence provider for EntityManager named simpleAppPU*: The following providers:
    oracle.toplink.essentials.PersistenceProvider
    oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider
    Returned null to createEntityManagerFactory.
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:154)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:83)
    I can't fix this. anybody know the solution??
    hanks, good work.

    Assalamu Alaikum,
    Check in persistence.xml whether persistence-unit is same in Persistence.createEntityManagerFactory*("simpleAppPU")* or not. It should be same.
    persistence.xml is like as follows:
    <?xml version="1.0" encoding="UTF-8"?>
    <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
    <persistence-unit name="*simpleAppPU*" transaction-type="RESOURCE_LOCAL">
    <provider>oracle.toplink.essentials.PersistenceProvider</provider>
    <class>Users</class>
    <properties>
    <property name="toplink.jdbc.user" value="root"/>
    <property name="toplink.jdbc.password" value="password"/>
    <property name="toplink.jdbc.url" value="jdbc:mysql://localhost:3306/innosched"/>
    <property name="toplink.jdbc.driver" value="com.mysql.jdbc.Driver"/>
    </properties>
    </persistence-unit>
    </persistence>

  • Newbie question about Java Studio Creator 2.

    HI all,
    I'm new to JSF and JSC.
    Below are some question which I hope those who has been working on JSF especially those that use JSC to provide me some advice.
    1. Can JSF application developed using JSC be changed or modified using other IDE in the market? Reason being I saw JSC include the position using style in the page. So, I wonder if I use JSC for JSF, will it contraint the future development or not, cos i don't want to be bound by one tool forever.
    2. Is the JSF component (eg. com.sun.rave.web...) provided by SUN are open source?
    3. What is the roadmap for JSC2? Will they continue its development?
    4. JSC2 is free, how about JSC3? Any idea whether it will be free?
    5. Do you think using JSC2 alone is not enough? where to build EJB or web services, we still need to use other tools like NetBeans? What do you use in combination with JSC2? Would like to know your experience.
    6. Can application developed using JSC be deployed to JBOSS?
    7. JSC uses JSF components from SUN (com.sun.rave.web...). So, when we deploy JSF application developed using JSC to tomcat or JBOss, do we need to purchase any license?
    8. I find JSC2 is quite resource hungry, sometimes thing reflect quite slowly. What is your experience using JSC2?
    Thank you.

    Can anyone advise me on my question?
    Thank you.

Maybe you are looking for

  • Why can I not install fonts? Office for Mac will not recognize them?

    My wife and I tried many times to install several fonts that we could use in Microsoft Office for Mac. Even though it said they were installed in the Mac, we could not see them in Word. We are new to the Apple products. We are not novice computer use

  • My iPhoto essentially deleted many of my videos

    At some point, I don't know when, iPhoto "deleted" a bunch of my videos. I didn't notice earlier because it left the thumbnails, but when I go to play the video, it does nothing and shows a runtime of 0:00. I had switched harddrives in my 2009 Macboo

  • Writing data in different intervals than DAQ

    Hallo Would anybody please know how to write data to a file in different timing than the actual acquisition? Actually I acquire seven different channels than I average every 100 points and what I would like to do is write this one average value of ea

  • Firefox Start now has autofill on the search. How can I stop this?

    Firefox Start, Google search used to have no autofill for searches When I type in a search I do not want to see suggestions for my search. This is extremely distracting. This is the only reason I use Firefox Start. Google will not let you opt out of

  • Websheets - sequence numbers for new rows

    Hi, I am creating a websheet application to use for a tasks/bug tracker for a project. I would really like the first column to be of a number format that is automatically filled with the next number in a sequence. This is quite necessary to have as t