Pessoal, já que existe um tópico sobre isso gostaria de tirar uma dúvida.
Tbm estou fazendo o relacionamento um pra muitos. Tipo: um curso tem várias disciplinas.
Vejam os meus POJOs:
[code]package hibernate;
public class Curso
{
// <editor-fold defaultstate=“collapsed” desc=“Propriedades”>
private String descricao;
private String nome;
private Disciplina disciplinas;
private Integer id;
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="Métodos">
public String getDescricao() {
return descricao;
}
public void setDescricao(String descricao) {
this.descricao = descricao;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Disciplina getDisciplinas() {
return disciplinas;
}
public void setDisciplinas(Disciplina disciplinas) {
this.disciplinas = disciplinas;
}
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="Construtor">
public Curso()
{ }
// </editor-fold>
}[/code]
E a implementação:
[code]Disciplina D1 = new Disciplina();
D1.setNome("Matemática");
D1.setEmenta("123456789");
Curso curso = new Curso();
curso.setNome("Supletivo");
curso.setDescricao("Descrição da disciplina em questão.");
D1.setCurso(curso);
curso.setDisciplinas(D1);
sessao.save(curso);[/code]
Mas está dando o seguinte erro:
[color=red]log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Initializing c3p0 pool… com.mchange.v2.c3p0.PoolBackedDataSource@15e83f9 [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@910040 [ acquireIncrement -> 2, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, idleConnectionTestPeriod -> 3000, initialPoolSize -> 2, maxIdleTime -> 5000, maxPoolSize -> 10, maxStatements -> 10, maxStatementsPerConnection -> 0, minPoolSize -> 2, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@12d3205 [ description -> null, driverClass -> null, factoryClassLocation -> null, jdbcUrl -> jdbc:mysql://localhost/hibernate?autoReconnect=true, properties -> {user=******, password=******} ] , preferredTestQuery -> null, propertyCycle -> 300, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, usesTraditionalReflectiveProxies -> false ] , factoryClassLocation -> null, numHelperThreads -> 3, poolOwnerIdentityToken -> 15e83f9 ]
Exception in thread "main" java.lang.ClassCastException: hibernate.Disciplina cannot be cast to java.util.Set
at org.hibernate.type.SetType.wrap(SetType.java:39)
at org.hibernate.event.def.WrapVisitor.processArrayOrNewCollection(WrapVisitor.java:83)
at org.hibernate.event.def.WrapVisitor.processCollection(WrapVisitor.java:50)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:104)
at org.hibernate.event.def.WrapVisitor.processValue(WrapVisitor.java:97)
at org.hibernate.event.def.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:58)
at org.hibernate.event.def.AbstractSaveEventListener.visitCollectionsBeforeSave(AbstractSaveEventListener.java:281)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:222)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:160)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:108)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:173)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:481)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:476)
at Hibernate.main(Hibernate.java:85)
Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)[/color]
O que posso fazer?