Spring j2ee

maha1987 Messages postés 101 Date d'inscription samedi 4 juin 2011 Statut Membre Dernière intervention 29 avril 2013 - 1 juil. 2011 à 20:44
maha1987 Messages postés 101 Date d'inscription samedi 4 juin 2011 Statut Membre Dernière intervention 29 avril 2013 - 1 juil. 2011 à 20:47
salut,
j'utilise myeclipse for spring pour la réalisation d'une application CRUD, le code est généré automatiquement,
le problème que j'utilise une table (test1) dont l'identifiant est auto_increment ,
comment peux_je changer le fichier TEST1.java(dont le code est le suivant) pour que puisse bénéficier de l'option auto_incrémentation
package dao.domain;

import java.io.Serializable;

import java.lang.StringBuilder;

import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

import javax.xml.bind.annotation.*;

import javax.persistence.*;

/**
*/

@Entity
@NamedQueries({
@NamedQuery(name "findAllTest1s", query "select myTest1 from Test1 myTest1"),
@NamedQuery(name "findTest1ByIdt", query "select myTest1 from Test1 myTest1 where myTest1.idt = ?1"),
@NamedQuery(name "findTest1ByNom", query "select myTest1 from Test1 myTest1 where myTest1.nom = ?1"),
@NamedQuery(name "findTest1ByNomContaining", query "select myTest1 from Test1 myTest1 where myTest1.nom like ?1"),
@NamedQuery(name "findTest1ByPrimaryKey", query "select myTest1 from Test1 myTest1 where myTest1.idt = ?1") })
@Table(catalog "mydata", name "test1")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace "runing/dao/domain", name "Test1")
public class Test1 implements Serializable {
private static final long serialVersionUID = 1L;

/**
*/

@Column(name "idt", nullable false)
@Basic(fetch = FetchType.EAGER)
@Id
@XmlElement
Integer idt;
/**
*/

@Column(name "nom", length 200)
@Basic(fetch = FetchType.EAGER)
@XmlElement
String nom;

/**
*/

/**
*/
public Integer getIdt() {
return this.idt;
}

/**
*/
public void setNom(String nom) {
this.nom = nom;
}

/**
*/
public String getNom() {
return this.nom;
}

/**
*/
public Test1() {
}

/**
* Copies the contents of the specified bean into this bean.
*
*/
public void copy(Test1 that) {
setIdt(that.getIdt());
setNom(that.getNom());
}

/**
* Returns a textual representation of a bean.
*
*/
public String toString() {

StringBuilder buffer = new StringBuilder();

buffer.append("idt=[").append(idt).append("] ");
buffer.append("nom=[").append(nom).append("] ");

return buffer.toString();
}

/**
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result (int) (prime * result + ((idt null) ? 0 : idt.hashCode()));
return result;
}

/**
*/
public boolean equals(Object obj) {
if (obj == this)
return true;
if (!(obj instanceof Test1))
return false;
Test1 equalCheck = (Test1) obj;
if ((idt == null && equalCheck.idt != null) || (idt != null && equalCheck.idt == null))
return false;
if (idt != null && !idt.equals(equalCheck.idt))
return false;
return true;
}
}

1 réponse

maha1987 Messages postés 101 Date d'inscription samedi 4 juin 2011 Statut Membre Dernière intervention 29 avril 2013
1 juil. 2011 à 20:47
le fichier test1.dao est
package dao.dao;

import dao.domain.Test1;

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.skyway.spring.util.dao.AbstractJpaDao;

import org.springframework.dao.DataAccessException;

import org.springframework.stereotype.Repository;

import org.springframework.transaction.annotation.Transactional;

/**
* DAO to manage Test1 entities.
*
*/
@Repository("Test1DAO")
@Transactional
public class Test1DAOImpl extends AbstractJpaDao<Test1> implements Test1DAO {

/**
* Set of entity classes managed by this DAO. Typically a DAO manages a single entity.
*
*/
private final static Set<Class<?>> dataTypes = new HashSet<Class<?>>(Arrays.asList(new Class<?>[] { Test1.class }));

/**
* EntityManager injected by Spring for persistence unit
*
*/
@PersistenceContext(unitName = "")
private EntityManager entityManager;

/**
* Instantiates a new Test1DAOImpl
*
*/
public Test1DAOImpl() {
super();
}

/**
* Get the entity manager that manages persistence unit
*
*/
public EntityManager getEntityManager() {
return entityManager;
}

/**
* Returns the set of entity classes managed by this DAO.
*
*/
public Set<Class<?>> getTypes() {
return dataTypes;
}

/**
* JPQL Query - findTest1ByIdt
*
*/
@Transactional
public Test1 findTest1ByIdt(Integer idt) throws DataAccessException {

return findTest1ByIdt(idt, -1, -1);
}

/**
* JPQL Query - findTest1ByIdt
*
*/

@Transactional
public Test1 findTest1ByIdt(Integer idt, int startResult, int maxRows) throws DataAccessException {
try {
return executeQueryByNameSingleResult("findTest1ByIdt", idt);
} catch (NoResultException nre) {
return null;
}
}

/**
* JPQL Query - findTest1ByNomContaining
*
*/
@Transactional
public Set<Test1> findTest1ByNomContaining(String nom) throws DataAccessException {

return findTest1ByNomContaining(nom, -1, -1);
}

/**
* JPQL Query - findTest1ByNomContaining
*
*/

@SuppressWarnings("unchecked")
@Transactional
public Set<Test1> findTest1ByNomContaining(String nom, int startResult, int maxRows) throws DataAccessException {
Query query = createNamedQuery("findTest1ByNomContaining", startResult, maxRows, nom);
return new LinkedHashSet<Test1>(query.getResultList());
}

/**
* JPQL Query - findTest1ByPrimaryKey
*
*/
@Transactional
public Test1 findTest1ByPrimaryKey(Integer idt) throws DataAccessException {

return findTest1ByPrimaryKey(idt, -1, -1);
}

/**
* JPQL Query - findTest1ByPrimaryKey
*
*/

@Transactional
public Test1 findTest1ByPrimaryKey(Integer idt, int startResult, int maxRows) throws DataAccessException {
try {
return executeQueryByNameSingleResult("findTest1ByPrimaryKey", idt);
} catch (NoResultException nre) {
return null;
}
}

/**
* JPQL Query - findAllTest1s
*
*/
@Transactional
public Set<Test1> findAllTest1s() throws DataAccessException {

return findAllTest1s(-1, -1);
}

/**
* JPQL Query - findAllTest1s
*
*/

@SuppressWarnings("unchecked")
@Transactional
public Set<Test1> findAllTest1s(int startResult, int maxRows) throws DataAccessException {
Query query = createNamedQuery("findAllTest1s", startResult, maxRows);
return new LinkedHashSet<Test1>(query.getResultList());
}

/**
* JPQL Query - findTest1ByNom
*
*/
@Transactional
public Set<Test1> findTest1ByNom(String nom) throws DataAccessException {

return findTest1ByNom(nom, -1, -1);
}

/**
* JPQL Query - findTest1ByNom
*
*/

@SuppressWarnings("unchecked")
@Transactional
public Set<Test1> findTest1ByNom(String nom, int startResult, int maxRows) throws DataAccessException {
Query query = createNamedQuery("findTest1ByNom", startResult, maxRows, nom);
return new LinkedHashSet<Test1>(query.getResultList());
}

/**
* Used to determine whether or not to merge the entity or persist the entity when calling Store
* @see store
*
*
*/
public boolean canBeMerged(Test1 entity) {
return true;
}
}
0
Rejoignez-nous