我的Enterprise Java Bean存在这个问题。 日志文件: stack trace
我不知道如何解决它!这是我的实体类:
$new = array();
$c = 1;
for($i=0;$i<count($a);$i++)
{
$sum =0;
for($k=0;$k<count($a[$i]);$k++)
{
$sum = $sum + $a[$i][$k]['buysell'];
}
$new[$i]['buysell'] = $sum;
$new[$i]['extracthour'] = $c;
$c++;
}
echo "<pre>";
print_r($new);
这是我的EJB:
Array
(
[0] => Array
(
[buysell] => 7350
[extracthour] => 1
)
[1] => Array
(
[buysell] => 480
[extracthour] => 2
)
)
这是我的persistence.xml:
package entities;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
/**
*
* @author gfucc
*/
@Entity
@NamedQueries({
@NamedQuery(name = "Student.findAll", query = "SELECT s FROM Students"),
@NamedQuery(name = "Student.findByMatr", query = "SELECT s FROM Student s WHERE s.matricola = :matricola"),
@NamedQuery(name = "Student.findByCognome", query = "SELECT s FROM Student s WHERE s.cognome = :cognome")
})
public class Student
{
@Id @GeneratedValue
private String matricola;
@NotNull
@Column(length = 100)
private String nome;
@NotNull
@Column(length = 100)
private String cognome;
@NotNull
@Column(length = 100)
private String corsoLaurea;
@NotNull
@Size(min = 0, max = 30)
private int numEsamiSostenuti;
public Student()
{
}
public Student(String nome, String cognome, String corsoLaurea, int numEsamiSostenuti) {
this.nome = nome;
this.cognome = cognome;
this.corsoLaurea = corsoLaurea;
this.numEsamiSostenuti = numEsamiSostenuti;
}
public String getMatricola() {
return matricola;
}
public void setMatricola(String matricola) {
this.matricola = matricola;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getCognome() {
return cognome;
}
public void setCognome(String cognome) {
this.cognome = cognome;
}
public String getCorsoLaurea() {
return corsoLaurea;
}
public void setCorsoLaurea(String corsoLaurea) {
this.corsoLaurea = corsoLaurea;
}
public int getNumEsamiSostenuti() {
return numEsamiSostenuti;
}
public void setNumEsamiSostenuti(int numEsamiSostenuti) {
this.numEsamiSostenuti = numEsamiSostenuti;
}
@Override
public String toString() {
return "Student{" +
"matricola=" + matricola +
", nome=" + nome +
", cognome=" + cognome +
", corsoLaurea=" + corsoLaurea +
", numEsamiSostenuti=" + numEsamiSostenuti + '}';
}
}
这是我的beans.xml:
package ejbs;
import entities.Student;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import qualifiers.Loggable;
/**
*
* @author gfucc
*/
@Stateless
@Loggable
public class StudentEJB implements StudentEJBRemote
{
@PersistenceContext(unitName = "StudentEJBPU")
private EntityManager em;
@Override
public Student createStudent(Student student)
{
em.persist(student);
return this.getStudentByMatricola(student.getMatricola());
}
@Override
public Student removeStudent(Student student)
{
Student toReturn = this.getStudentByMatricola(student.getMatricola());
if(toReturn != null)
{
em.remove(student);
return toReturn;
}
return null;
}
@Override
public Student updateStudent(Student student)
{
return em.merge(student);
}
@Override
public List<Student> getStudentList()
{
TypedQuery<Student> query = em.createNamedQuery("Student.findAll", Student.class);
return query.getResultList();
}
@Override
public Student getStudentByMatricola(String matricola)
{
TypedQuery<Student> query = em.createNamedQuery("Student.findByMatr", Student.class);
query.setParameter(1, matricola);
return query.getSingleResult();
}
@Override
public Student getStudentByCognome(String cognome)
{
TypedQuery<Student> query = em.createNamedQuery("Student.findByCognome", Student.class);
query.setParameter(1, cognome);
return query.getSingleResult();
}
}
现在,在这些图片中,您可以看到我的项目结构: project structure
有什么问题?我都是。我连接的数据库,我使用默认数据库“示例”...问题是在持久性单元上,因为没有它我可以构建,然后部署没有问题!请帮忙。非常感谢