tenho essas classes.
HibernateUtil
package services;
import java.lang.reflect.ParameterizedType;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.flex.remoting.RemotingInclude;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.SessionFactoryUtils;
public class AbstractService<T> {
protected Class<T> classVO = null;
public HibernateTemplate template;
SessionFactory sessionFactory;
public AbstractService()
{
this.classVO = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
}
@Autowired
public void setSessionFactory(SessionFactory sessionFactory)
{
template = new HibernateTemplate(sessionFactory);
}
@RemotingInclude
public void add(T t) throws Exception
{
this.template.save(t);
}
@RemotingInclude
public void update(T t)
{
this.template.update(t);
}
@RemotingInclude
public void del(T t)
{
this.template.delete(t);
}
@RemotingInclude
public List<T> findAll()
{
return template.find(String.format("from %s", this.classVO.getName()));
}
@RemotingInclude
public List<T> findByExample(T t)
{
return this.template.findByExample(t);
}
}
Tenho a class Clientes
@Entity
@Table(name="CLI_CLIENTES")
public class CliClienteVO implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@SequenceGenerator(name="CLI_CLIENTES_IDCLIENTE_GENERATOR", sequenceName="CLI_SQ_CLIENTES")
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="CLI_CLIENTES_IDCLIENTE_GENERATOR")
@Column(name="ID_CLIENTE", unique=true, nullable=false, precision=9)
private long idCliente;
E na class Enderecos eu uso a class Cliente como chave composta
@Entity
@Table(name="CLI_ENDERECOS")
public class CliEnderecosVO implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
private CliEnderecoVOPK id;
@Column(nullable=false, length=80)
private String bairro;
@Column(nullable=false, precision=8)
private BigDecimal cep;
@Column(nullable=false, length=100)
private String complemento;
@Column(nullable=false, length=80)
private String endereco;
@Column(nullable=false, precision=9)
private BigDecimal numero;
//bi-directional many-to-one association to CliClienteVO
@ManyToOne
@JoinColumn(name="ID_CLIENTE", nullable=false, insertable=false, updatable=false)
private CliClienteVO cliCliente;
Que por sua vez tive que criar a class
@Embeddable
public class CliEnderecoVOPK implements Serializable {
//default serial version id, required for serializable classes.
private static final long serialVersionUID = 1L;
@Column(name="ID_CLIENTE", unique=true, nullable=false, precision=9)
private long idCliente;
como faço para salvar um endereço usando a Class AbstractService