JTable binding using JPA

Hi,
I'm having a database table containing blob column that contains image for each row. Also I'm having a JTable in front end to display existing records of database using Toplink(JPA).
My requirement is as follows
1) code snippet to bind & persist the image into database column which was selected from frontend (I'm displaying the image on jlabel using filechooser).
2) retrieving the saved image on a JLabel when ever I select a row in front end JTable.
I hope you understood my intend.
looking forward for your response.
Regards,
Chandu

Hi Chandu,
If you are using JDeveloper for generating the bindings for model persist and binding code will be generated by JDeveloper.
TopLink/JPA wizard will identify the type of column and generate Entities.When you create a SessionEJB and generate datacontrol,persist operation will bind the input data(in this case image) to a table column.
Regards,
Vinay

Similar Messages

  • How to use JPA in a worker thread?

    I'm using WebLogic 10.3.5.0 with JPA 2.0 and have the following scenario:
    - user needs to start a task takes some time to complete;
    - this task needs to read and write to DB;
    One solution would be to write a worker and use the WorkManager feature to start this from an session EJB.
    How should I use JPA from this worker to access the DB in a transactional manner?

    You should be able to use it as normal.
    Your worker class is probably not injected like your SessionBean, so you would either need to pass the EntityManager, or look it up either through JNDI if container managed, or Persistence if application managed.
    For transactions, you either need to use JTA directly if using JTA, or use JPA transactions if using RESOURCE_LOCAL.

  • Using JPA Entity-Objects defined in other EJB-Development Component

    Hello Community,
    I'm working on a Java-Application on NW CE 7.1, using JEE5 Beans in the Business-Logic-Layer and WebDynpro/Java in the UI-Layer.
    I designed a Bean for working with data, stored in a database-table of the system-database.
    For that addtionally i created a class, representing the Entity-Object, in the same Development-Component of Type EJB 3.0.
    It looks like this:
    @NamedQueries ({
         @NamedQuery (name="findAllSdCust", query="SELECT c from SdCust c ORDER BY c.kdnr"),
         @NamedQuery (name="findSdCustByKdnr", query="SELECT c from SdCust c WHERE c.kdnr = :kdnr"),
         @NamedQuery (name="findSdCustByIlnnr", query="SELECT c from SdCust c WHERE c.ilnnr = :ilnnr")
    @Entity
    @Table(name="ZKALL_SD_CUST")
    public class SdCust implements Serializable {
         @Id
         @TableGenerator (name="idGenerator", table="ZKALL_ID_GEN", pkColumnName="GEN_KEY", valueColumnName="GEN_VALUE", initialValue=100)
         @GeneratedValue (strategy=GenerationType.TABLE, generator="idGenerator")
         private long id;
         private String name;
         private String lname;
         private String kdnr;
         private String ilnnr;
         private long connid;
         private long cnt;
         @Version
         private long version;
          Constructor, Getter and Setter methods follow here
    The corresponding bean looks like this
    @Stateless(name="SdCustBean")
    public class SdCustBean implements SdCustLocal {
         @PersistenceContext (unitName="xyz")
         private EntityManager em;
         public SdCust getSdCustByKdnr (String kdnr)
              SdCust result = new SdCust();
              // List<Manufacturer> resultList = new ArrayList<Manufacturer>();
              Query  myQuery = em.createNamedQuery("findSdCustByKdnr");
              myQuery.setParameter("kdnr", kdnr);
              result = (SdCust) myQuery.getSingleResult();
              return result;
         public void setEM (EntityManager iem)
              em = iem;
           // other methods .....
    After that i created a new Development-Component of Enterprise Application-Type and added above DC to this EAR-DC. I also supplied the nessecary descriptor-files/Enries in EJB-DC and EAR-DC.
    When now using this bean from WebDynpro with the Web-Dypro EJB-Model-Import everything works fine.
    The bean returns the desired object(s).
    But now i created a new DC of type EBJ 3.0
    This DC contains a Message Driven Bean. That MDB is a Job-Bean which i want to schedule. That  Bean uses JRA to connect to an SAP-Abap-System to read some Data and should use JPA to insert/upate/delete the read data in the Database. This should work as a simple replication for my application.
    I assigned that EJB-DC containing the MDB to a new EAR-DC together with job-definition-xml and the neccessary entries in deployment-descriptors.
    After deploying i see the corresponding job-defition in the NW scheduler using the administrator-views.
    I'm also able to schedule the job and it executes fine. Connecting to SAP-Abap System also works fine using JRA.
    But JPA does not work!!!!!
    I created an dependency from my EAR-DC containing the Job EJB-DC and to the EJB-DC containing the Entity-Class.
    I tried three diferent things to get i running, but all of them failed.
    1.)
    The part  looks like:
    public class MasterDataReplicateJobBean extends MDBJobImplementation implements MessageListener
      @EJB SdCustBean mybean;
       public void onJob(JobContext ctx) throws Exception {
            SdCust sdCust = mybean.getSdCustByKdnr (mykdnr);
    Compiles fine. But this fails because the Data is stored in the system-database. The exception says, that i have to use a datasource which supports 2-Phase commit. I know, that i could possibly solve this problem by annotation the Method getSdCustByKdnr with the Annotation for the Transaction-Manager to use REQUIRES_NEW Transaction. But i dont want to generally annotate my methods this way.
    2.)
    This part looks like this
    public class MasterDataReplicateJobBean extends MDBJobImplementation implements MessageListener
    @PersistenceContext (unitName="xyz")
    private EntityManager em;
       public void onJob(JobContext ctx) throws Exception {
         SdCust cust = new SdCust();
         Query  myQuery = em.createQuery("SELECT c from SdCust c WHERE c.kdnr = :kdnr");
         myQuery.setParameter("kdnr", dbkdnr);
         cust = (SdCust) myQuery.getSingleResult();
    This also results in a runtime-exception because the entity-Manager cant resolve SdCust from the Query as an Object. The Exception is:
    java.lang.IllegalArgumentException: line 1: Abstract Schema Type 'SdCust' doesn't exist
    SELECT c from SdCust c WHERE c.kdnr = :kdnr
    3.) and last try so far:
    public class MasterDataReplicateJobBean extends MDBJobImplementation implements MessageListener
    @PersistenceContext (unitName="xyz")
    private EntityManager em;
       public void onJob(JobContext ctx) throws Exception {
         SdCustBean custBean = new SdCustBean();
         custBean.setEM(em);
         SdCust cust = custBean.getSdCustByKdnr(kdnr);
    In this example i use the Bean from the beginning not as a bean itself but as a normal class. that class has an addtional Method setEM to set the Entity-Manager (which is injected when using the class as a bean)
    In that way i got the exception, that the named Query "findSdCustByKdnr" cannot be found by the entity-manager.
    It seems to me, that i can access the class, but that all annotations belonging to JPA for that class are not recognized.
    Does anybody can give me a hint to solve this problem? Did i forgot something important?
    best regards
    matthias hayk
    Edited by: Matthias Hayk on Feb 5, 2009 9:38 AM

    I was already on wright trace.
    My class "SdCust" was not recognized by the Entity-Manager as an Entity-Class.
    This relies on the storage of the entity-class and where the Entity-Manager looks for entity-classes.
    By default it seems to look for all classes in the same jar file. thats the reason why everything works fine when the using bean and the entity-class are in the same project.
    In my last case, the using bean is in another  development-component and so also in anohter jar file. in this case the entity-manager must be told where to find entity-classes.
    this is done in the persistence.xml file.
    i added the line
    <jar-file>xxx.yyy.com~mdata_beans.jar</jar-file>
    underneath the <persistence-unit>-tag.
    This works.
    regards
    Matthias Hayk

  • Weird issue with merge using JPA...?

    Hi all,
    I have the following code snippet (HsTrans has a manytoone relation with Hss), Hss is the parent
                HsTrans hsTrans = new HsTrans();
             Hss hss=em.find(Hss.class, studyId);
             hsTrans.setStudy(studyId);
             hsTrans.setState(state.toString());
             hsTrans.setTimestamp(timeOfState);
             hss.getHsTrans().add(hsTrans); //Add child to aprent
             hsTrans.setHss(hss);                //Child Parent
                em.merge(hss);  // Does not work Throws a Unique Key violation error
    Whereas replacing the same with this
             Hss hss2=hsStudyTrans.getHsStudy(); 
                em.merge(hss2); // Works fine
       Does anyone know if this is a JPA bug or some other issue.
    Thx
    VR

    RainaV wrote:
    Does anyone know if this is a JPA bug or some other issue.JPA is a specification, so it has no bugs (only design flaws). If there is a bug somewhere it is in the persistence provider you are using, but most likely it is just you not understanding how merge and transaction management in general works. I've written dozens of applications now that use JPA and I think I really needed merge a grand total of once.
    In this snippet you provide, you are apparently making the 'hss' object managed through the em.find() method. This means that any changes you make to it will be made persistent as soon as the transaction is committed. You don't need to call merge() at all, you only call that on entities that are detached.
    Now for the actual problem of unique key violation, I don't even see you committing hsTrans. Change the code to this:
    HsTrans hsTrans = new HsTrans();
    Hss hss=em.find(Hss.class, studyId);
    hsTrans.setStudy(studyId);
    hsTrans.setState(state.toString());
    hsTrans.setTimestamp(timeOfState);
    hsTrans.setHss(hss); // set managed hss object
    em.persist(hsTrans); // persist hsTrans and make it managed
    hss.getHsTrans().add(hsTrans); // add the new managed hsTrans to the hss mapped collection

  • Guidelines for using  JPA from an Add-on?

    Can somebody post the guidelines for using JPA from within an Add-on?
    We are facing issues using JPA (2.0)
    Thanks
    Pramod

    From http://www.sxipper.com/faq#uninstall
    To uninstall Sxipper go to your Firefox menu and choose Tools | Add-ons. Select '''Sxipper '''from the list of extensions and click the "Uninstall" button. After restarting your browser Sxipper will be removed.
    Sxipper still uses the Firefox Password Manager, so your passwords are all there. Uninstalling Sxipper will restore the default password manager functionality. See http://www.sxipper.com/faq#wherepassword

  • Problem when using JPA/EJB in webservice

    I wrote a web service that use JPA/EJB to connect to Sybase (the existing tables), and deployed to OC4J, but it got the following error when the web service is invoked:
    <env:Envelope
      xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
      xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:ns0="http://prjtestws_9/types/">
     <env:Body>
      <env:Fault>
       <faultcode>env:Server</faultcode>
       <faultstring>Internal Server Error (Caught exception while handling request: java.lang.NullPointerException)</faultstring>
      </env:Fault>
     </env:Body>
    </env:Envelope>
    I have checked that, the query will return some records, and also it works fine if the program executed as a stand alone application.
    Thanks in advance

    I find that I can only have ONE webservice that using JPA/EJB for an OC4J instance, if more than one then the above error will come out, and I have to restart the OC4J instance to run another webservice that using JPA/EJB.
    Is there any solution for this issue?
    Thanks

  • HOw to get  DatabaseMetaData using JPA

    hi;
    I am using ejb3 , jpa for database connectivity .is there any way to get the metadata about the database in JPA.
    ie:- in JDBC we can use DatabaseMetaData for getting this. HOw can we get the Database Meta Data by using JPA.
    Regards
    Irshad

    In addition to Gurvinder references, go over the productCatalog.xml or customCatalog.xml file to know the properties in each item-descriptor of ProductCatalog.
    In your requirement skuid is same as repositoryId.
    If you are using in jsp then use SKULookUp droplet to get the sku repositoryItem.
    If you need it in java code then use catalogTools.findSKU(String skuid).
    Peace
    Shaik

  • Config to use JPA 2.0 in eclipse for weblogic portal 10.3.2

    Hi,
    can anyone help me to config eclipse for WLP 10.3.2 for using JPA 2.0
    Thanks!

    Hi,
    The following EclipseLink JPA tutorial for WebLogic 10.3.2 (EclipseLink 1.2 is shipped in the modules directory on WebLogic) is Eclipse IDE based and includes details on getting your EAR deployed and debuggable via the Eclipse 3.4/3.5 EE edition IDE. This is via the WebLogic server plugin or via the OEPE. Source is included for all EAR, EJB and WAR projects as well as the SE DDL generation project to setup your database.
    The following tutorial and EclipseLink 2.0 wiki sites are the most current versions
    http://wiki.eclipse.org/EclipseLink/Examples/JPA/WebLogic_Web_Tutorial
    http://wiki.eclipse.org/EclipseLink/Development/JPA_2.0/weblogic
    thank you
    /michael
    http://www.eclipselink.org

  • Why can't i use JPA?

    i am using Eclipse. i installed Java EE 1.6.24.
    However, i cannot access: javax.persistence.*, it doesn't even show up in content assist. i realized this could be an Eclipse thing, but does anyone have anything else i can check?
    should i go look in the actual java jar file and see if the package exists?
    any help is appreciated....

    Kayaman wrote:
    pedron wrote:
    in Eclipse the entire API is (usually) available and ready for import. However, for me the entire javax.persistence.* is NOT available at all. Since when? Also what do you consider "the entire API"?
    All my projects have a suitable library in the project path (usually with the source code or at least the javadoc attached). Which library does your project have?Look, like i said, i'm new to this, that's why i came to the forum to ask the question. i've used a bunch of different stuff in Eclipse. I know about importing jars, libraries, all that stuff.
    However, i've googled how to use JPA and it says that it's part of Java EE 6, which i've installed and am now using in Eclipse as my active JRE. (I've been using 1.6 for awhile, but i just installed 1.6.24.)
    As far as i have seen in my, albeit limited, experience, is that libraries that are said to be in the Java EE 6 (like, for instance, annotations) are just there, with no special library import. I can get content assist to find, for instance, javax.annotation.*, but not javax.persistence.*, and that's where i'm confused.
    So, maybe i don't know libraries very well, that's fine. But i've never seen it said anywhere that i've read that i need to import some special library to run JPA. Is this the case? I'm not trying to burden the forum. i've done some research and am looking to find what i'm lacking in information. the snide comments don't help anyone... (not yours)
    thanks

  • If an app uses JPA with a WAR, where does persistence.xml go?

    If I'm constructing an app using JPA entities, but just in a WAR file, not an EAR file, as I'm not using the other EJB components, where does the persistence.xml file get deployed to? Is it just WEB-INF/classes, or do I have to do something like WEB-INF/classes/META-INF (one resource i saw implied this)?

    david.karr wrote:If I'm constructing an app using JPA entities, but just in a WAR file, not an EAR file, as I'm not using the other EJB components, where does the persistence.xml file get deployed to? Is it just WEB-INF/classes, or do I have to do something like WEB-INF/classes/META-INF (one resource i saw implied this)?Yes, put it in WEB-INF/classes/META-INF. If you're using JDeveloper or Eclipse Webtools and you put the persistence.xml in src\META-INF compiling will put it into WEB-INF\classes\META-INF for you.
    --Shaun                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Is JBO exception working when using JPA ?

    I am using Jdeveloper 11g R (11.1.2.3) & weblogic 10 G
    In my pages I use JSF & Facelet
    Is JBO exception working when using JPA as data provider?
    I mean can I throw JBO exception from my back end in some business cases?
    thanks
    Mohsen

    You haven't added a resource reference for your web application that gives the application a local name for the global resource "UserDatabase".

  • Updating a JTable when using an AbstractTableModel

    Hi,
    I have tried to create a JTable with an AbstractTableModel but I am obviously missing something in all the tutorials and examples as I cannot get the table to update when using my model.
    My application reads data in from a CSV file that is selectable at run time, but I have written a small app that demonstrates the problem I am having.
    If you uncomment the DefaultTableModel lines of code all is OK, but I need to use my Abstract Class as I intend to colour certain rows and add a Boolean column, that I would like to display as a CheckBox and not just the String representation.
    Any help would be great as I am tearing my hair out here!!
    My Test Class
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import java.util.*;
    public class TestTable extends JFrame implements ActionListener
    private JPanel jpTestTable = new JPanel();          
    private Vector vColumnNames = new Vector();
    private Vector vCellValues = new Vector();
    private DefaultTableModel dtmTestTable;
    private CustomTableModel ctmTestTable;
    private JTable jtTestTable;
    private JScrollPane jspTestTable;
    private JButton jbGo = new JButton();
         public TestTable()
         dtmTestTable = new DefaultTableModel();
         ctmTestTable = new CustomTableModel();
         //jtTestTable = new JTable( dtmTestTable );  //using this instead of my CustomModel works fine
         jtTestTable = new JTable( ctmTestTable );
         jtTestTable.setAutoCreateRowSorter(true);
         jtTestTable.setFillsViewportHeight( true );
         jspTestTable = new JScrollPane( jtTestTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS ,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );
         jspTestTable.setBounds( 10, 10, 350, 400 );
         jspTestTable.setBorder( BorderFactory.createLoweredBevelBorder() );
         jbGo.setText( "Go" );
         jbGo.setBorder( BorderFactory.createRaisedBevelBorder() );
         jbGo.setBounds( 125, 430, 100, 25 );
         jbGo.addActionListener(this);
         jpTestTable.setLayout( null );
         jpTestTable.setBounds( 0, 0, 375, 500 );     
         jpTestTable.add( jspTestTable );
         jpTestTable.add( jbGo );
         this.setTitle( "Test Table" );
         this.getContentPane().setLayout( null );
         this.setBounds( 200, 50, 375, 500 );
         this.getContentPane().add( jpTestTable );
         this.setResizable( false );
         public void actionPerformed( ActionEvent e )
         updateTable();
         public void updateTable()
         vColumnNames.add( "Please" );
         vColumnNames.add( "work" );
         vColumnNames.add( "you" );
         vColumnNames.add( "git!" );
         vColumnNames.trimToSize();
         Vector vRow = new Vector();
              for( int i = 0; i < 10; i++ )
                   for( int x = 0; x < vColumnNames.size(); x++ )
                        vRow.add( "" + i + "" + x );
              vCellValues.add( vRow );
         //dtmTestTable.setDataVector( vCellValues, vColumnNames );  //using this instead of my CustomModel works fine
         ctmTestTable.setDataVector( vCellValues, vColumnNames );
         public void processWindowEvent(WindowEvent e)
         super.processWindowEvent(e);
              if(e.getID() == WindowEvent.WINDOW_CLOSING)
              exit();
         public void exit()
         System.exit( 0 );     
         public static void main(String args[])
         TestTable tt = new TestTable();
         tt.setVisible( true );
    }And my CustomTableModel Class
    import javax.swing.*;
    import javax.swing.table.*;
    import java.awt.*;
    import java.util.*;
    public class CustomTableModel extends AbstractTableModel
    protected Vector columnIdentifiers  = new Vector();
    protected Vector dataVector = new Vector();
         public CustomTableModel()
         public CustomTableModel( Vector data, Vector columnNames )
         setDataVector( data, columnNames );
         public int getColumnCount()
         return columnIdentifiers.size();
         public int getRowCount()
         return dataVector.size();
         public String getColumnName( int col )
         return "" + columnIdentifiers.get( col );
         public Object getValueAt( int row, int col )
         Vector vRow = new Vector();
         vRow = (Vector) dataVector.get( row );
         return (Object) vRow.get( col );
         public Class getColumnClass(int c)
         return getValueAt(0, c).getClass();
         public boolean isCellEditable(int row, int col)
              if (col < 2)
                   return false;
              else
                   return true;
         public void setValueAt( Object value, int row, int col )
         Vector vTemp = (Vector) dataVector.get( row );
         Vector<Object> vRow = new Vector<Object>();
              for( int i = 0; i < vTemp.size(); i++ )
                   vRow.add( (Object) vTemp.get( i ) );
         vRow.remove( col );
         vRow.add( col, value );
         vRow.trimToSize();     
         dataVector.remove( row );
         dataVector.add( row, vRow );
         dataVector.trimToSize();
         fireTableCellUpdated(row, col);
         public void setDataVector( Vector data, Vector columnNames )
         columnIdentifiers  = (Vector) columnNames.clone();
         dataVector = (Vector) data.clone();
         fireTableDataChanged();
    }I have just tried adding the following code after reading another example, but same result - arrrrrrrgggggggghhhhhhhhh!!!!
    ctmTestTable = (CustomTableModel) jtTestTable.getModel();
    ctmTestTable.fireTableDataChanged();Edited by: Mr_Bump180 on Jul 28, 2008 2:51 PM

    Hi camickr,
    Well that is good news as my Abstact class is about as much good as an ashtray on a motorbike. I think I must have misread or misunderstood the Table Tutorials as I thought I had to use an Abstrat class to get colurs based on conditions and to get Check Boxes to represent Boolean variables.
    I am clearly struggling with this concept - which I have never used before - do you know of any tutorials, that explain how to update a JTable with file data at runtime, as all the ones I have looked at set it as part of the java code - which is no good to me.
    Also am I overriding the DefaultTableModel Class correctly - I have written a seperate Model class but wounder if I need to include it in with my JTable class. I was trying to make it generic so I didn't have to write one for each JTable - but as I can't get it to work I should perhaps try to walk before I run.
    I'm not asking for the code, but just a guide to how close I am to where I want to be, and some links to tutorials that are closer to what I want to achieve. I will reread the Java Table Tutorial tonight - and you never know the penny may drop all on it's own this time!!!
    Thanks

  • HTTP Binding using POST Method

    Hi all,
    I need to pass XML to a BPEL using HTTP POST. I have got a sample running for passing information to BPEL through GET method of HTTP. But do not have any idea about how to pass XML using HTTP POST. Please put forward your suggestions.
    Thanks.
    John

    Thanks Marc.
    Let me rephrase the scenario.
    I have an external application which is capable of sending information only in XML through HTTP requests. It does not send SOAP messages. I guess in this case, we would need to use the HTTP binding using POST method. Much like the sample at http://blogs.oracle.com/reynolds/2005/09/invoking_bpel_from_an_html_for.html which uses the GET method.
    In this sample reynolds is using the GET method. I have been trying to get the POST method to work.
    Regards
    John

  • Can't use JPA facet in a Workshop 10.3 EJB project

    Greetings,
    I'm using Oracle Workshop for WebLogic 10.3 to migrate an enterprise application from JBoss 5.0 to WebLogic 10.3. I'm a bit confused as, while I can add the JPA facet to a Dynamic Web project, I cannot do the same with an EJB project. I'd need to take advantage of the IDE automatic facets management instead to manually dealing with libraries and dependencies. I beleive that this is the reason these facets exist. However, after having created a EJB 3.0 project, it is impossible to add to it the JPA facet. I had to define the JPA entities in a Dynamic Web project as this is the only one to which I can add the JPA facet. This is not regular. Additionally, the SLSB facades may only be defined in an EJB project. They reference the JPA entities in the Dynamic Web project which, given the class loading hierarchy, is not possible. So my question is: how is one supposed to use JPA with WTP projects ?
    Many thanks in advance for any help,
    Nicolas

    This isn't supported in Workshop 10.3 and prior, the JPA tooling only works with Dynamic Web Projects in those releases to my knowledge.
    I think this changed in OEPE 11g. Check out this article that shows JPA being used in the context of a Utility Project:
    http://www.oracle.com/technology/pub/articles/cioroianu-eclipse-jpa.html
    OEPE 11g Download: http://www.oracle.com/technology/software/products/oepe/index.html

  • How to get fixed results using JPA

    Hi
    I have a table with lot of rows, when I querry, it is taking a lot of time and I am displaying that many rows in UI in single table. So it is not scaling well.
    SO I am planing to show x number of row in on page. So for that to achieve, how do I querry the db (derby) using JPA to get first 25 rows, next 25 rows...
    I appricate any help
    thanks

    i think you can have a serial number column in your table and you keep track of that serial number. I mean pass it to your method along with the size of page. Lets say if the number starts from 0 then you can calculate the first page using starting number + page size, if your page size is 25 then you will get 0+25 =25 and you can use the result to query from database like;
    select * from myTable where rowNo<=25
    You can store this number (Now 25) in user's session and pass it to the method.

Maybe you are looking for