ejb3 Entitymanager throw NullPointerException
up vote
0
down vote
favorite
I have a problem. When I want to persist an object Test, I have a exception who tell that My entitymanager is null.
I have a Ejb project with my EntityBean Test.
I have a EAR with a server Wildfly.
I have a java project with my Main.
It's a big problem because I can't insert, find or use any objects.
Thank you.
My files are here.
My SessionBean
@Stateless
@LocalBean
public class SessionBean implements ISessionBean {
@PersistenceContext(unitName="FirstEM")
EntityManager em;
public SessionBean() { }
@Override
public void testT() {
try {
Test t = new Test("bla", "blok");
em.persist(t);
}
catch(Exception e) {
System.out.println(em.toString());
System.out.println(e.getStackTrace());
System.out.println(e.getMessage());
System.out.println(e.toString());
}
}
}
My entity bean Test
@Entity
public class Test implements Serializable {
@Id
@GeneratedValue
private int id;
private String nom, prenom;
public Test(){ }
public Test(String nom, String prenom){
this.nom = nom;
this.prenom = prenom;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
public String getPrenom() {
return prenom;
}
public void setPrenom(String prenom) {
this.prenom = prenom;
}
}
And my Main class
public class Main {
public static void main(String args) {
SessionBean sb = new SessionBean();
System.out.println("Welcome.");
sb.testT();
System.out.println("Bye.");
}
}
java-ee wildfly ejb-3.0 entitymanager entity-bean
New contributor
mm98 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
|
show 14 more comments
up vote
0
down vote
favorite
I have a problem. When I want to persist an object Test, I have a exception who tell that My entitymanager is null.
I have a Ejb project with my EntityBean Test.
I have a EAR with a server Wildfly.
I have a java project with my Main.
It's a big problem because I can't insert, find or use any objects.
Thank you.
My files are here.
My SessionBean
@Stateless
@LocalBean
public class SessionBean implements ISessionBean {
@PersistenceContext(unitName="FirstEM")
EntityManager em;
public SessionBean() { }
@Override
public void testT() {
try {
Test t = new Test("bla", "blok");
em.persist(t);
}
catch(Exception e) {
System.out.println(em.toString());
System.out.println(e.getStackTrace());
System.out.println(e.getMessage());
System.out.println(e.toString());
}
}
}
My entity bean Test
@Entity
public class Test implements Serializable {
@Id
@GeneratedValue
private int id;
private String nom, prenom;
public Test(){ }
public Test(String nom, String prenom){
this.nom = nom;
this.prenom = prenom;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
public String getPrenom() {
return prenom;
}
public void setPrenom(String prenom) {
this.prenom = prenom;
}
}
And my Main class
public class Main {
public static void main(String args) {
SessionBean sb = new SessionBean();
System.out.println("Welcome.");
sb.testT();
System.out.println("Bye.");
}
}
java-ee wildfly ejb-3.0 entitymanager entity-bean
New contributor
mm98 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
if you do run your App in the Wildfly container, why do you have a main method?
– triplem
Nov 17 at 11:40
@triplem I don't understand, where do you want to put my main method ?
– mm98
Nov 17 at 12:02
The ApplicationServer is the process, running the application, therefor the application does not need any "main" method. If you would like to create an own application, you should not use wildfly.
– triplem
Nov 17 at 12:05
@triplem Because, I have to do a work for my school with a client-server application. And I must make a server-side administrator.
– mm98
Nov 17 at 12:09
If this is school-work, then please read the documentations and scripts you got, shouldn't be too hard. Keep in mind, that the server-side (wildfly) does the handling of the application. On the client is is different, you do have the control over the lifecycle of the application (as long as it is a rich client).
– triplem
Nov 17 at 12:12
|
show 14 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a problem. When I want to persist an object Test, I have a exception who tell that My entitymanager is null.
I have a Ejb project with my EntityBean Test.
I have a EAR with a server Wildfly.
I have a java project with my Main.
It's a big problem because I can't insert, find or use any objects.
Thank you.
My files are here.
My SessionBean
@Stateless
@LocalBean
public class SessionBean implements ISessionBean {
@PersistenceContext(unitName="FirstEM")
EntityManager em;
public SessionBean() { }
@Override
public void testT() {
try {
Test t = new Test("bla", "blok");
em.persist(t);
}
catch(Exception e) {
System.out.println(em.toString());
System.out.println(e.getStackTrace());
System.out.println(e.getMessage());
System.out.println(e.toString());
}
}
}
My entity bean Test
@Entity
public class Test implements Serializable {
@Id
@GeneratedValue
private int id;
private String nom, prenom;
public Test(){ }
public Test(String nom, String prenom){
this.nom = nom;
this.prenom = prenom;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
public String getPrenom() {
return prenom;
}
public void setPrenom(String prenom) {
this.prenom = prenom;
}
}
And my Main class
public class Main {
public static void main(String args) {
SessionBean sb = new SessionBean();
System.out.println("Welcome.");
sb.testT();
System.out.println("Bye.");
}
}
java-ee wildfly ejb-3.0 entitymanager entity-bean
New contributor
mm98 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I have a problem. When I want to persist an object Test, I have a exception who tell that My entitymanager is null.
I have a Ejb project with my EntityBean Test.
I have a EAR with a server Wildfly.
I have a java project with my Main.
It's a big problem because I can't insert, find or use any objects.
Thank you.
My files are here.
My SessionBean
@Stateless
@LocalBean
public class SessionBean implements ISessionBean {
@PersistenceContext(unitName="FirstEM")
EntityManager em;
public SessionBean() { }
@Override
public void testT() {
try {
Test t = new Test("bla", "blok");
em.persist(t);
}
catch(Exception e) {
System.out.println(em.toString());
System.out.println(e.getStackTrace());
System.out.println(e.getMessage());
System.out.println(e.toString());
}
}
}
My entity bean Test
@Entity
public class Test implements Serializable {
@Id
@GeneratedValue
private int id;
private String nom, prenom;
public Test(){ }
public Test(String nom, String prenom){
this.nom = nom;
this.prenom = prenom;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
public String getPrenom() {
return prenom;
}
public void setPrenom(String prenom) {
this.prenom = prenom;
}
}
And my Main class
public class Main {
public static void main(String args) {
SessionBean sb = new SessionBean();
System.out.println("Welcome.");
sb.testT();
System.out.println("Bye.");
}
}
java-ee wildfly ejb-3.0 entitymanager entity-bean
java-ee wildfly ejb-3.0 entitymanager entity-bean
New contributor
mm98 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
mm98 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
mm98 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked Nov 17 at 10:56
mm98
12
12
New contributor
mm98 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
mm98 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
mm98 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
if you do run your App in the Wildfly container, why do you have a main method?
– triplem
Nov 17 at 11:40
@triplem I don't understand, where do you want to put my main method ?
– mm98
Nov 17 at 12:02
The ApplicationServer is the process, running the application, therefor the application does not need any "main" method. If you would like to create an own application, you should not use wildfly.
– triplem
Nov 17 at 12:05
@triplem Because, I have to do a work for my school with a client-server application. And I must make a server-side administrator.
– mm98
Nov 17 at 12:09
If this is school-work, then please read the documentations and scripts you got, shouldn't be too hard. Keep in mind, that the server-side (wildfly) does the handling of the application. On the client is is different, you do have the control over the lifecycle of the application (as long as it is a rich client).
– triplem
Nov 17 at 12:12
|
show 14 more comments
if you do run your App in the Wildfly container, why do you have a main method?
– triplem
Nov 17 at 11:40
@triplem I don't understand, where do you want to put my main method ?
– mm98
Nov 17 at 12:02
The ApplicationServer is the process, running the application, therefor the application does not need any "main" method. If you would like to create an own application, you should not use wildfly.
– triplem
Nov 17 at 12:05
@triplem Because, I have to do a work for my school with a client-server application. And I must make a server-side administrator.
– mm98
Nov 17 at 12:09
If this is school-work, then please read the documentations and scripts you got, shouldn't be too hard. Keep in mind, that the server-side (wildfly) does the handling of the application. On the client is is different, you do have the control over the lifecycle of the application (as long as it is a rich client).
– triplem
Nov 17 at 12:12
if you do run your App in the Wildfly container, why do you have a main method?
– triplem
Nov 17 at 11:40
if you do run your App in the Wildfly container, why do you have a main method?
– triplem
Nov 17 at 11:40
@triplem I don't understand, where do you want to put my main method ?
– mm98
Nov 17 at 12:02
@triplem I don't understand, where do you want to put my main method ?
– mm98
Nov 17 at 12:02
The ApplicationServer is the process, running the application, therefor the application does not need any "main" method. If you would like to create an own application, you should not use wildfly.
– triplem
Nov 17 at 12:05
The ApplicationServer is the process, running the application, therefor the application does not need any "main" method. If you would like to create an own application, you should not use wildfly.
– triplem
Nov 17 at 12:05
@triplem Because, I have to do a work for my school with a client-server application. And I must make a server-side administrator.
– mm98
Nov 17 at 12:09
@triplem Because, I have to do a work for my school with a client-server application. And I must make a server-side administrator.
– mm98
Nov 17 at 12:09
If this is school-work, then please read the documentations and scripts you got, shouldn't be too hard. Keep in mind, that the server-side (wildfly) does the handling of the application. On the client is is different, you do have the control over the lifecycle of the application (as long as it is a rich client).
– triplem
Nov 17 at 12:12
If this is school-work, then please read the documentations and scripts you got, shouldn't be too hard. Keep in mind, that the server-side (wildfly) does the handling of the application. On the client is is different, you do have the control over the lifecycle of the application (as long as it is a rich client).
– triplem
Nov 17 at 12:12
|
show 14 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
mm98 is a new contributor. Be nice, and check out our Code of Conduct.
mm98 is a new contributor. Be nice, and check out our Code of Conduct.
mm98 is a new contributor. Be nice, and check out our Code of Conduct.
mm98 is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53350519%2fejb3-entitymanager-throw-nullpointerexception%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
if you do run your App in the Wildfly container, why do you have a main method?
– triplem
Nov 17 at 11:40
@triplem I don't understand, where do you want to put my main method ?
– mm98
Nov 17 at 12:02
The ApplicationServer is the process, running the application, therefor the application does not need any "main" method. If you would like to create an own application, you should not use wildfly.
– triplem
Nov 17 at 12:05
@triplem Because, I have to do a work for my school with a client-server application. And I must make a server-side administrator.
– mm98
Nov 17 at 12:09
If this is school-work, then please read the documentations and scripts you got, shouldn't be too hard. Keep in mind, that the server-side (wildfly) does the handling of the application. On the client is is different, you do have the control over the lifecycle of the application (as long as it is a rich client).
– triplem
Nov 17 at 12:12