users@glassfish.java.net

Re: MS SQL Server 2000 for JDBC with NetBeans IDE 5.5 and Java EE 5

From: <glassfish_at_javadesktop.org>
Date: Mon, 07 May 2007 05:00:22 PDT

Hi marc,

I have also tried this with other names but its giving the same error.

Please can you advise is the code below correct and is Java Persistence is compatible with SQL Server 2000 database:

My Users Entity Class:

[b]/*
 * Users.java
 *
 * Created on May 6, 2007, 7:15 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package commerc;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Id;
import java.io.Serializable;
import java.*;
/**
 * Entity class Users
 *
 * @author deepak
 */
@Entity
public class Users implements Serializable {

    @Id
    //_at_GeneratedValue(strategy = GenerationType.AUTO)
    //private Long id;
    private String MSISDN;
    private String FirstName;
    private String LastName;
    private String Password;
    private String address;
    private int BrokerAcc;
    private int age;
    private String DeviceID;
    
    /** Creates a new instance of Users */
   // public Users() {
    //}

    /**
     * Gets the id of this Users.
     * @return the id
     */
   // public Long getId() {
   // return this.id;
    //}

    /**
     * Sets the id of this Users to the specified value.
     * @param id the new id
     */
  // public void setId(Long id) {
  // this.id = id;
  // }

    /**
     * Returns a hash code value for the object. This implementation computes
     * a hash code value based on the id fields in this object.
     * @return a hash code value for this object.
     */
// @java.lang.Override
// public int hashCode() {
// int hash = 0;
// hash += (this.getId() != null ? this.getId().hashCode() : 0);
// return hash;
// }
            

    /**
     * Determines whether another object is equal to this Users. The result is
     * <code>true</code> if and only if the argument is not null and is a Users object that
     * has the same id field values as this object.
     * @param object the reference object with which to compare
     * @return <code>true</code> if this object is the same as the argument;
     * <code>false</code> otherwise.
     */
        
/**
    @java.lang.Override
    public boolean equals(java.lang.Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Users)) {
            return false;
        }
        Users other = (Users)object;
        if (this.getId() != other.getId() && (this.getId() == null || !this.getId().equals(other.getId()))) return false;
        return true;
    }
 */

    /**
     * Returns a string representation of the object. This implementation constructs
     * that representation based on the id fields.
     * @return a string representation of the object.
     */
    /**
    @java.lang.Override
    public java.lang.String toString() {
        return "commerc.Users[id=" + getId() + "]";
    }*/
    
    @java.lang.Override
    public java.lang.String toString() {
        return "commerc.Users[id=" + getMSISDN() + "]";
    }

    public String getMSISDN() {
        return MSISDN;
    }

    public void setMSISDN(String MSISDN) {
        this.MSISDN = MSISDN;
    }

    public String getFirstName() {
        return FirstName;
    }

    public void setFirstName(String FirstName) {
        this.FirstName = FirstName;
    }

    public String getLastName() {
        return LastName;
    }

    public void setLastName(String LastName) {
        this.LastName = LastName;
    }

    public String getPassword() {
        return Password;
    }

    public void setPassword(String Password) {
        this.Password = Password;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public int getBrokerAcc() {
        return BrokerAcc;
    }

    public void setBrokerAcc(int BrokerAcc) {
        this.BrokerAcc = BrokerAcc;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getDeviceID() {
        return DeviceID;
    }

    public void setDeviceID(String DeviceID) {
        this.DeviceID = DeviceID;
    }
    
}[/b]


This is my Session bean for above entity class

[b]/*
 * UsersFacade.java
 *
 * Created on May 7, 2007, 10:01 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package commerc;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author deepak
 */
@Stateless
public class UsersFacade implements UsersFacadeLocal {

    @PersistenceContext
    private EntityManager em;
    
    /** Creates a new instance of UsersFacade */
    public UsersFacade() {
        
    }

    public void create(Users users) {
        em.persist(users);
    }

    public void edit(Users users) {
        em.merge(users);
    }

    public void destroy(Users users) {
        em.merge(users);
        em.remove(users);
    }

    public Users find(Object pk) {
        return (Users) em.find(Users.class, pk);
    }

    public List findAll() {
        return em.createQuery("select object(o) from Users as o").getResultList();
    }

    public void persist(Object object) {
        // TODO:
        // em.persist(object);
    }
    
}[/b]
[Message sent by forum member 'deepak1234' (deepak1234)]

http://forums.java.net/jive/thread.jspa?messageID=215810