2 Replies Latest reply on Aug 29, 2007 3:09 AM by Alexandru Enache

    datasource testing

    Alexandru Enache Newbie

      Hi,

      I have a small question. I've configured SEAM to use MySQL. And I want to do some small testing with it.

      myapp-ds.xml

      <datasources>
       <local-tx-datasource>
       <jndi-name>myTestDataSource</jndi-name>
       <connection-url>jdbc:mysql://localhost:3306/test</connection-url>
       <driver-class>com.mysql.jdbc.Driver</driver-class>
       <user-name>mytestuser</user-name>
       <password>mytestpass</password>
       <metadata>
       <type-mapping>mySQL</type-mapping>
       </metadata>
       </local-tx-datasource>
      </datasources>


      persistence.xml
      <persistence>
       <persistence-unit name="myTestDB">
       <provider>org.hibernate.ejb.HibernatePersistence</provider>
       <jta-data-source>java:/myTestDataSource</jta-data-source>
       <properties>
       <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
       <property name="hibernate.hbm2ddl.auto" value="none"/>
       </properties>
       </persistence-unit>
      </persistence>


        • 1. Re: datasource testing
          Alexandru Enache Newbie

          Sorry I submited it, instead of previewing it :D. I'll continue my question here.

          And I have the following bean:

          @Entity
          @Name("user")
          @Scope(SESSION)
          @Table(name="test")
          public class User implements Serializable {
           private static final long serialVersionUID = 1881413500711441951L;
          
           private int varsta;
           private String prenume;
           private String nume;
           private int id;
          
           public User(String newName, String newForname, int newAge, int newId) {
           nume = newName;
           prenume = newForname;
           varsta = newAge;
           id = newId;
           }
          
           public User() {
           System.out.println("========USER CREATED==========");
           }
          
           @NotNull
           public String getNume() {
           return nume;
           }
          
           public void setNume(String newName) {
           nume = newName;
           }
          
           @NotNull
           public String getPrenume() {
           return prenume;
           }
          
           public void setPrenume(String newForname) {
           prenume = newForname;
           }
          
           @NotNull
           public int getVarsta() {
           return varsta;
           }
          
           public void setVarsta(int newAge) {
           varsta = newAge;
           }
          
           @Id @NotNull
           public int getId() {
           return id;
           }
          
           public void setId(int newId) {
           id = newId;
           }
          
           @Override
           public String toString() {
           return "User(" + nume + prenume + ")";
           }
          }


          This was basicly took from seam's registering example and modified a bit.
          My table is:
          nume varchar(20)
          prenume varchar(20)
          id int not null auto_increment, primary key

          And on a page I have a very basic controller:
          <h:outputText value="User name=#{user.nume}"/>

          All this is enough in order for the bean to retrieve the info from the DB ?? cuz it doens't work :(.

          Best regards,
          Alex Enache

          • 2. Re: datasource testing
            Alexandru Enache Newbie

            the db also has a "varsta" field, of type int ... I've missed that.