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.");
}
}









share|improve this question







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















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.");
}
}









share|improve this question







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













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.");
}
}









share|improve this question







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






share|improve this question







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.











share|improve this question







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.









share|improve this question




share|improve this question






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


















  • 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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






mm98 is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















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






























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.










 

draft saved


draft discarded


















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.















 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Paul Cézanne

UIScrollView CustomStickyHeader Resize height generates problems when scroll is too fast

Angular material date-picker (MatDatepicker) auto completes the date on focus out