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

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

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

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

  • Limit query for Java Persistence Query Language

    Hi,
    Anybody know Java Persistence Query Language can support limit querry to limit the number of row return(Like SQL LIMIT clause)?
    Thanks

    I think the javax.persistence.Query methods setFirstResult and setMaxResults are what you need...

  • 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

  • Isolation level 0 and java persistence frameworks

    Hi,
    i use www.castor.org as my persistence framework, castor have have its own lock engine and cache for entities, then i think to avoid some table lock in database to pass for JDBC connection the parameter isolation=0, as any update or write is made and controlled by castor in castor i dont have dirty data, anyone have experience with any other java persistence engine and used maxdb with lock engine managed by framework?
    any insight about this are welcome.
    best regards
    Clóvis

    > Hi,
    >
    > i use www.castor.org as my persistence framework, castor have have its own lock engine and cache for entities, then i think to avoid some table lock in database to pass for JDBC connection the parameter isolation=0, as any update or write is made and controlled by castor in castor i dont have dirty data, anyone have experience with any other java persistence engine and used maxdb with lock engine managed by framework?
    >
    Sure
    The whole SAP NetWeaver stack runs with isolation level 0.
    Works quite fine.
    In fact there are certain features (like the count(*) optimization) that don't work consistently with isolation level 1 (read commited).
    So you shouldn't get into trouble with that.
    regards,
    Lars

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

  • 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

  • Simple Object Modelling and Java IDE for OSX?

    I haven't been technical for a while and I want to refresh my Java and object modelling skills. I'm looking for two things. If I can find both in the same environment so much the better.
    1) A basic UML modelling tool. All I really care about is describing a medium size object model: classes, sub-classes, attributes, relations, etc.
    2) A basic Java IDE. Don't need EJB or anything complex. Just want to compile run and debug simple Java programs.
    I down loaded Net Objects but it seems like overkill for what I want. I looked on some open source sites but almost nothing was native to OSX it all ran under Windows or required a Java virtual machine. Actually I guess that's another question, is there already a Java virtual machine as part of OSX or do I need to download one and if so which would be the best.
    I'm willing to spend a few $$ but free stuff would be better and no more than $50. So far I found one product native to OSX but the starting cost was $400+ for a five person license.

    In case anyone has the same question, I just found this very nice tool on the Apple web site called Visual Paradigm for UML:
    http://www.apple.com/downloads/macosx/development_tools/visualparadigmforumlente rpriseedition.html
    I'm still getting to know it but this is exactly what I was looking for. Fairly easy to use if you already know OO but not as complex as some other tools and works well on the Mac.

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

  • Jakarta POI and Java Excel API

    I recently downloaded both these as I'm trying to create an application that reads information from an excel file. However, the problem I am having is that I just don't know where to start. When I download the files and unzip them, I haven't a clue where to put the files or how to call them from my java files. I've read the help files on both the websites but am no clearer on what to do. Any help would be much appreciated.

    Download an IDE like Eclipse or JBuilder. Set-up the POI or JExcel JAR files on your new project's class path. Import the relevant packages into the class that will use them. Start typing, autocomplete will help give you a list of classes and methods that are available.
    If the above is confusing, start over. Go back and re-read how to import external JAR's onto a classpath. Try to use another third-party API to get the hang of it. Then, do it with POI. Follow the examples, even copy-paste a class into your own source tree and try to compile. Gradually, build up your expertise. Now, go to the Javadocs. You should have the ability to use any class or method published in the API.
    - Saish

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

Maybe you are looking for

  • Bank keys selection on F110

    Hi All, In the Customer master data ->payment transaction, There are two bank keys (of same country) with different Partner Bank Type 'A' , 'B' are assigned In F110 For the documents of type Direct bank collect, for some documents selected the first

  • Audio CD disappears after confirming impoty into iTunes

    Setup: Hardware: New Macbook Pro 15" Software: Preinstalled software no modifications or additions solely upgrades. When I try to import a CD into iTunes the following occurs: 1 The CD is displayed on the Desktop as Audio CD. 2 iTunes queries Graceno

  • Office outlook Calendar Sync

    I have a 20GB colour click wheel IPod purchased late 2004. Windows is XP with SP2 installed and updated regularly. ITunes is the latest edition. Microsoft Office is 2003 edition. Problem is that I am trying to sync my Microsoft Office Outlook calenda

  • How much longer until Reader 8.0 support???

    How much longer do we have to wait until ACF's can be used with Adobe Reader 8.0?  This is causing us some pain with our customers because they install Reader 8.0 only to find out that it does not support ACF.  Reader 8 has been out 4 months now, how

  • Update Equipment BOM using Function module (very urgent)

    Hi All, I am an ABAPER and trying to update equipemnt BOM. I want to update equipment BOM using a function module. I am currently using 'CSAI_BOM_MAINTAIN' function module. But i am not able to update the Equipment BOM. After function call the sy-sub