facebook

sql server, jpa, newby here reporting in!!!!

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 15 posts - 1 through 15 (of 27 total)
  • Author
    Posts
  • #311205 Reply

    JamesRaynor
    Member

    hello everyone

    i am new to this ide, and i was trying the jpa example from the tutorial section with the difference that i want to try it out with sql server 2008, and i get a little confused when i reverse enginere it creates all of the classes the tutorial says, plus one more.

    it creates the following:

    entitymanager
    example
    exampleDAO
    IexampleDAO
    and
    exampleID…
    ?????????
    whats that one for?
    i tried doing the rest of the tutorial but it didnt work it gives errors of conectivity
    and i checked the code and exampleID is the pojo, and example is something else i dont understand.

    and just for the heck of it i tried the example of the hibernate section and it was fine until i used the hql part of the tutorial. just did the the from hql and got weird things.

    well the question here is:
    how do i do the example correctly with sqljdbc4.jar, sqlserver 2008 and myeclipse 8.5 on winXP?

    #311208 Reply

    JamesRaynor,
    Can you clarify if a primary key is defined on your table? The extra class is generated when there is no primary key defined on the table.
    If you have not defined the key, can you create a primary key, remove all the generated files and reverse engineer again?
    Let me know how that works for you.

    #311219 Reply

    JamesRaynor
    Member

    thanks, yes i think that the table i am using has no PK i’ll try it

    #311220 Reply

    JamesRaynor
    Member

    thank you shalini
    that was the problem

    #311221 Reply

    JamesRaynor
    Member

    all most forgot
    what if i want to use a table without a pk?

    because i redid the example
    but the table i am supossed to use does not allow me to create a PK
    what must i do differently to do the example?

    #311230 Reply

    JamesRaynor,
    You can go by the same lines as given in the tutorial.
    The only difference would be creating and accessing your table object. You need to do that by creating an instance of
    xxxId.
    Let me know if you need any further assistance.

    #311248 Reply

    JamesRaynor
    Member

    i tried it but i got an error(s)
    my code for the application is:

    
    public class runJPA {
    
        public static void main(String[] args) {
    
    //        var just to fill a fake table
            double d = 10;
            String t = "estado";        
    //        my instance
            PruebaId id = new PruebaId(d, d, t, d, t, d, t, t, t, d, t, d, d); 
    //        i dont remember why i put this, so just ignore it
            System.out.println(id);
    //        to verify if the instance is filled with the right info
            System.out.println(id.getCveEdo() + " " + id.getNomEdo());
    //        the DAO
            PruebaDAO dao = new PruebaDAO();
    //        the TX
            EntityManagerHelper.beginTransaction();
            dao.save(id);
            EntityManagerHelper.commit();
        }
    
    }

    at the dao.save(id) it asked me to chenge pruebaDAO, so i did. now its like

    public void save(PruebaId entity) {

    instead of

    public void save(Prueba entity) {

    and asked to implement IpruebaDAO.save

    and it gets the following result:

    PruebaId@ab898151
    10.0 estado
    78  dgcvPU  INFO   [main] openjpa.Runtime - Starting OpenJPA 1.2.0
    219  dgcvPU  INFO   [main] openjpa.jdbc.JDBC - Using dictionary class "org.apache.openjpa.jdbc.sql.SQLServerDictionary".
    Exception in thread "main" <openjpa-1.2.0-r422266:683325 nonfatal general error> org.apache.openjpa.persistence.PersistenceException: There were errors initializing your configuration: <openjpa-1.2.0-r422266:683325 fatal user error> org.apache.openjpa.util.UserException: A connection could not be obtained for driver class "com.microsoft.sqlserver.jdbc.SQLServerDriver" and URL "jdbc:sqlserver://localhost:1433;databaseName=Jv".  You may have specified an invalid URL.
        at org.apache.openjpa.jdbc.schema.DataSourceFactory.newConnectException(DataSourceFactory.java:256)
        at org.apache.openjpa.jdbc.schema.DataSourceFactory.installDBDictionary(DataSourceFactory.java:242)
        at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getConnectionFactory(JDBCConfigurationImpl.java:692)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.openjpa.lib.conf.ConfigurationImpl.instantiateAll(ConfigurationImpl.java:288)
        at org.apache.openjpa.conf.OpenJPAConfigurationImpl.instantiateAll(OpenJPAConfigurationImpl.java:1432)
        at org.apache.openjpa.kernel.AbstractBrokerFactory.makeReadOnly(AbstractBrokerFactory.java:646)
        at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:183)
        at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:142)
        at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:192)
        at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:145)
        at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:56)
        at EntityManagerHelper.getEntityManager(EntityManagerHelper.java:29)
        at EntityManagerHelper.beginTransaction(EntityManagerHelper.java:42)
    //      at runJPA.main(runJPA.java:21)
    Caused by: java.lang.NumberFormatException: For input string: "JDBC"
        at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
        at java.lang.Integer.parseInt(Integer.java:447)
        at java.lang.Integer.parseInt(Integer.java:497)
        at org.apache.openjpa.jdbc.sql.SQLServerDictionary.connectedConfiguration(SQLServerDictionary.java:92)
        at org.apache.openjpa.jdbc.sql.DBDictionary.decorate(DBDictionary.java:4157)
        at org.apache.openjpa.lib.jdbc.DecoratingDataSource.decorate(DecoratingDataSource.java:100)
        at org.apache.openjpa.lib.jdbc.DecoratingDataSource.getConnection(DecoratingDataSource.java:94)
        at org.apache.openjpa.jdbc.schema.DataSourceFactory.installDBDictionary(DataSourceFactory.java:234)
        ... 16 more
    
        at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:196)
        at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:142)
        at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:192)
        at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:145)
        at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:56)
        at EntityManagerHelper.getEntityManager(EntityManagerHelper.java:29)
        at EntityManagerHelper.beginTransaction(EntityManagerHelper.java:42)
        at runJPA.main(runJPA.java:21)
    Caused by: java.lang.RuntimeException: There were errors initializing your configuration: <openjpa-1.2.0-r422266:683325 fatal user error> org.apache.openjpa.util.UserException: A connection could not be obtained for driver class "com.microsoft.sqlserver.jdbc.SQLServerDriver" and URL "jdbc:sqlserver://localhost:1433;databaseName=Jv".  You may have specified an invalid URL.
        at org.apache.openjpa.jdbc.schema.DataSourceFactory.newConnectException(DataSourceFactory.java:256)
        at org.apache.openjpa.jdbc.schema.DataSourceFactory.installDBDictionary(DataSourceFactory.java:242)
        at org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getConnectionFactory(JDBCConfigurationImpl.java:692)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.openjpa.lib.conf.ConfigurationImpl.instantiateAll(ConfigurationImpl.java:288)
        at org.apache.openjpa.conf.OpenJPAConfigurationImpl.instantiateAll(OpenJPAConfigurationImpl.java:1432)
        at org.apache.openjpa.kernel.AbstractBrokerFactory.makeReadOnly(AbstractBrokerFactory.java:646)
        at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:183)
        at org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:142)
        at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:192)
        at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:145)
        at org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:56)
        at EntityManagerHelper.getEntityManager(EntityManagerHelper.java:29)
        at EntityManagerHelper.beginTransaction(EntityManagerHelper.java:42)
        at runJPA.main(runJPA.java:21)
    Caused by: java.lang.NumberFormatException: For input string: "JDBC"
        at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
        at java.lang.Integer.parseInt(Integer.java:447)
        at java.lang.Integer.parseInt(Integer.java:497)
        at org.apache.openjpa.jdbc.sql.SQLServerDictionary.connectedConfiguration(SQLServerDictionary.java:92)
        at org.apache.openjpa.jdbc.sql.DBDictionary.decorate(DBDictionary.java:4157)
        at org.apache.openjpa.lib.jdbc.DecoratingDataSource.decorate(DecoratingDataSource.java:100)
        at org.apache.openjpa.lib.jdbc.DecoratingDataSource.getConnection(DecoratingDataSource.java:94)
        at org.apache.openjpa.jdbc.schema.DataSourceFactory.installDBDictionary(DataSourceFactory.java:234)
        ... 16 more
    
        at org.apache.openjpa.lib.conf.ConfigurationImpl.instantiateAll(ConfigurationImpl.java:302)
        at org.apache.openjpa.conf.OpenJPAConfigurationImpl.instantiateAll(OpenJPAConfigurationImpl.java:1432)
        at org.apache.openjpa.kernel.AbstractBrokerFactory.makeReadOnly(AbstractBrokerFactory.java:646)
        at org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:183)
        ... 7 more
    

    the first line is the id
    the second one is the data that is inserted
    and the slashes indicate what i think is the problem or maybe what i did in the pruebaDAO was wrong. i dont know the errors confuse me.

    so what can i do and what i did wrong?

    #311265 Reply

    JamesRaynor,

    A connection could not be obtained for driver class “com.microsoft.sqlserver.jdbc.SQLServerDriver” and URL “jdbc:sqlserver://localhost:1433;databaseName=Jv”. You may have specified an invalid URL.

    This looks like a driver related issue. Are you able to connect to the database from DB Browser?
    Can you send us a screen shot showing your connector configuration in the DB Browser? You can use the PM button at the end of the post to send the screen shot.

    #311286 Reply

    JamesRaynor,
    Thank you for the screen shots. I could not replicate this at my end. Can you give us a few more details?
    1. When you say that the unsupported column type is string, is that a varchar coulumn that you are referring to?
    Can you send us the DDL of the table you are using?
    2. did you choose Microsoft Sql Server /Microsoft Sql Server 2005 when creating the driver template?

    #311292 Reply

    JamesRaynor
    Member

    1. when i say is string i meant that the column is type nchar. the ddl is

    USE [Jv]
    GO
    
    /****** Object:  Table [dbo].[prueba3]    Script Date: 09/14/2010 09:49:17 ******/
    SET ANSI_NULLS ON
    GO
    
    SET QUOTED_IDENTIFIER ON
    GO
    
    CREATE TABLE [dbo].[prueba3](
        [folio] [int] NOT NULL,
        [tonterias] [nchar](10) NULL,
     CONSTRAINT [PK_prueba3] PRIMARY KEY CLUSTERED 
    (
        [folio] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    
    GO
    

    2. yes i chose sql server 2005, although i have 2008 , i tried to edit it end stopped working, and with that i started to check all of the other sql server options, the only that works is sql server 2005 driver template

    #311315 Reply

    JamesRaynor,
    I could replicate this at my end and I have raised a PR with the dev team.
    As a work around, you need to update the OpenJPA jar files. The following are the steps –
    1. Download OpenJPA1.2.2 jar file from http://openjpa.apache.org/downloads.html
    2. Go to Window > Preferences > MyEclipse > Project Capabilities > JPA > OpenJPA tab.
    3. Select OpenJPA1.2.0 and click “Remove”
    4. Click “Add Jar/Zip” and browse to the OpenJPA1.2.2 jar file and click OK.
    Now retry your example. Please note that this will update all the projects using OpenJPA.
    Let me know how this works for you.

    #311316 Reply

    JamesRaynor,
    For the issue regarding <Unsupported> being displayed when the query is executed in sql editor,
    try using the jtds driver to connect to the data base.
    Let me know how that works for you.

    #311433 Reply

    JamesRaynor
    Member

    thank you for the advice shalini,
    i m new to that driver and dont know how it works, i tried finding something on the internet, found something in

    http://jtds.sourceforge.net/faq.html

    but the info just overwhelmed me, and i am getting connection test failures. i am using this conection url:

    jdbc:jtds:sqlserver://localhost:4133/JV;user=sa,password=dg

    how do i write it wright?

    #311435 Reply

    JamesRaynor,
    From the DB browser, you need not specify the user name and password in the connection URL.
    Please refer to the attached screen shots for further reference.
    Let me know if that helps.

    Attachments:
    You must be logged in to view attached files.
    #311443 Reply

    JamesRaynor
    Member

    thanks a lot!!!!!!!!!!!! :p
    that was the problem

Viewing 15 posts - 1 through 15 (of 27 total)
Reply To: sql server, jpa, newby here reporting in!!!!

You must be logged in to post in the forum log in