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.

Similar Messages

  • 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 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

  • 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.

  • 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

    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

  • 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>

  • 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?

  • 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

  • Java Persistence API + mySQL and East Europe characters

    Hi,
    I use Sun Application Server 9.0 and mySQL 4.1.20 on Linux. When I put data (with jsf form) into my database table everything is displayed correctly until I restart application server (or redeploy my web app). After restarting server non-ascii characters look strange. I suppose that there is a problem with character coding (between apps server and database) but I can't find any solution. I use UTF-8 character coding both in database fields and for displaying jsf pages.
    There are't any problems when I use Derby database for starage data.
    Thanks

    Can you give some more information ?
    Are you using netbeans 5.5 or doing this program standalone and interfacing
    directly with appserver ?
    Can you send a pointer to a gif of the incorrect looking characters ?
    Can you elaborate about putting data using jsf form and some details
    or extract from the code that writes or reads the data ?
    Do the names of your table or columns have the european characters
    in them or is it just the data ?
    Thanks for your help.
    >
    Thanks
    Hi,
    I use Sun Application Server 9.0 and mySQL 4.1.20 on
    Linux. When I put data (with jsf form) into my
    database table everything is displayed correctly
    until I restart application server (or redeploy my
    web app). After restarting server non-ascii
    characters look strange. I suppose that there is a
    problem with character coding (between apps server
    and database) but I can't find any solution. I use
    UTF-8 character coding both in database fields and
    for displaying jsf pages.
    There are't any problems when I use Derby database
    for starage data.
    Thanks

  • Persistence API newbie question

    Hello everybody!
    I am new at J2EE development, so can you explain me some details. We're curently do J2EE application at work and using J2EE 1.5 features(EJB 3.0, Persistence etc..). I don't understand exactly what lies under annotations. Let's take Persistence API. All anotations and classes is in javax.persistence package. What is that package, where it come from? Is it located in container or where? In fact I would like to use Persistence API on sites managed by Apache Tomcat Server. Is it possible, what classes do I need? Another question is it is possible to use that API at Swing Applications, and what do I need to do this.
    Please, explain me little of where all that stuff come from.
    Thank you!

    anotations and classes is in javax.persistence
    package. What is that package, where it come from? Is
    it located in container or where? Java Persistence API (JPA) is part of JavaEE 5 platform, and so is available in all JavaEE 5 compliant application servers. In JavaEE SDK 5, these classes are in lib/javaee.jar. JPA is also available as a standalone technology. There are several products that are implementing this technology, like Hibernate, TopLink, or OpenJPA.
    The specification:
    http://jcp.org/en/jsr/detail?id=220
    Persistence Part in JavaEE 5 Tutorial (Part Four: Persistence )
    http://java.sun.com/javaee/5/docs/tutorial/doc/
    In fact I would
    like to use Persistence API on sites managed by
    Apache Tomcat Server. Is it possible, what classes do
    I need? Another question is it is possible to use
    that API at Swing Applications, and what do I need to
    do this. They are all possible ways of using JPA. See JavaEE 5 Tutorial for more details. The newly released NetBeans 5.5 has nice support for developing and deploying JPA applications. NetBeans site has a lot of resources on this topic. For example:
    http://www.netbeans.org/kb/55/persistence_ontomcat.html
    http://www.netbeans.org/kb/articles/hibernate-javaee.html
    -cheng

  • Persistence outside EJB

    Hi
    I am developing a web app with tomcat and JSF and apache derby db. I want to use the java persistence api to talk to the DB. (Note: I am not using the EJBs here)
    I would like to know if this possible or should I just go with hibernate. This application will reside in an embedded device with good processing power.
    So please also suggest adding java persistence or hibernate would be a big overhead compared to the plain JDBC access. If so how much would be the overhead
    thanks

    Absolutely. The Java Persistence API was designed to be usable from outside the EJB tier.
    You can use it from within other Java EE tiers such as the web tier or Application Client tier,
    or outside of a Java EE environment altogether.
    The Java Persistence API was developed as part of the EJB 3.0 JSR but in future releases
    it will be evolved as its own specification.
    You can find some more information here :
    https://glassfish.dev.java.net/javaee5/persistence/
    --ken                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Java persistence: sequence generator not working in expected way.

    Hi,
    I just played around with java persistence api and found that sequence generator annotations for making new primary key value not working correctly in my code. following is part of my code related to this problem.
    in entity class:
    @SequenceGenerator(name="mySeq", sequenceName="MY_SEQ_IN_DB")
    @Id
    @GeneratedValue(strategy=SEQUENCE, generator="mySeq")
    @Column(name = "UPLOAD_ID", nullable = false)
    private Integer uploadId;
    I have a sequence called MY_SEQ_IN_DB in my oracle 9i testing db. When I ran the code to save a new entity instance to database I found that the new upload id is not the one that should be created from the MY_SEQ_IN_DB sequence, while the sequence was not increased either. It's instead something starting from 97 (in my pc), and increased just like a sequence, but every time I reran my code the sequence restarted itself again beginning with 97(of course the insert failed with primary key conflict). the behavior just looks like it's a sequence created and managed totally by the persistence api or toplink itself (I guess).
    So, my question is, is this a designed behavior or have I done something wrong to make it not using the correct sequence in the db?
    I used hibernate before, and assigning new primary key from sequence in this way works fine.
    Thanks
    JC.L

    There are some things in Java which can't be serialized. When contained within a higher-level class such as Buttons. A button can be associated with an Action Listener. Now, you can serialize a button; however you can't serialize an action listener - for what should be to you obvious reasons. This is NOT an error and so there is no need to throw an exception when serializing the button.
    Basically: Applet sends servlet button, but not listener.

  • Persistence API on SJS Application Server

    Hello.
    how can i use toplink essentials classes on SJS Application Server Platfor Edition 9? Or, how can i control over client transactions?
    Is there any examples?
    Thanks.

    You can find more information in the Java EE 5 tutorial or in the Java Persistence API glassfish page :
    http://java.sun.com/javaee/5/docs/tutorial/doc/
    https://glassfish.dev.java.net/javaee5/persistence/
    --ken                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • EJB 3.0 Persistence API and Stored Procedures

    Does the EJB 3.0 Persistence API in any way prescribe or facilitate the use of Stored Procedure calls? Given the recent popularity of using (database) server APIs consisting of Stored Procedures that are addressed by ORM frameworks for performing the DML operations and of course the general usefulness of stored procedures for specific data related operations, there definitely is a need for clarity on using the straightforward Persistence operations in combination with calls to Stored Procedures. Can we use the Native Query for executing CallableStatements? Can we get to a Connection instance from the EntityManager? Can we easily use the results from a Stored Procedure invocation to refresh our Domain Objects - or is that all application logic in which the EntityManager cannot help us?
    If the spec does not help us at this point, do you know how TopLink will deal with this topic?
    Thanks for any help you can give me!
    Best regards,
    Lucas Jellema

    I'm am also interested in a response to this post. I've just upgraded to JDeveloper 10.1.3.1 and am interested in making calls to stored procedures.
    I've found examples of just creating my own session beans but it seems I would have to hard code the datasource name. Does anyone know if I can get around this using the entity manager supplied by the tool?
    thanks,
    Dan

Maybe you are looking for

  • Media Keys Not Working - Apple Wireless Keyboard - Snow Leopard 10.6

    Hello, I am a new user to this Support Area and i tried calling but as its Christmas Day i cant get through because there closed so i decided to join here. Ok basically my problem is that i have a iMac and i recently installed Snow Leopard and on Chr

  • Single Maintenance plan creation for multiple equipemnts with different cyc

    Dear Experts, I had a following scenario to map in PM module. can anybody guide me to map this process? we had no.of equipments under one functional location and will go through preventive maintenance on yearly basis. For this, i will create the sing

  • P6N SLI Platinum random shutdowns

    System: MSI P6N SLI Platinum MoBo Intel E6750 CPU Etasis 850W PSU Corsair CM2X1024-6400C4 RAM (using only 1 stick while troubleshooting) MSI NX8600GTS GPU OK, this is a strange one. I put my new system together and everything seemed to be working fin

  • Can't get installer to work - times out at 41%

    How do I get an update to install for adobe reader? The update installer keeps timing out at 41% after a few seconds. I have disabled my accdelerator and my antivirus but it keeps happening, both with Firefox and Internet Explorer.

  • Changed network name and now e-print e-mail address doesn't work

    I have a 6500A Plus Deskjet.  I have an hpconnected account and changed my e-print e-mail address to something I would remember.  Then I changed the name of my network.  I have to get a new claim code ..... I enter it and when I try to choose my e-pr