0
How use EntityManagerFactory just one time?
When i run app my login form opens and after insert data click ok to open my main form, so i open EntityManagerFactory two time. First in login form and second in main form. How can open just one time?
3 Answers
+ 2
try implement singleton design pattern to your EntityManagerFactory.
singleton limit a class to only have a single instance, but you can call/use that instance almost everywhere as long as you have the access to that class
0
ïżŒthank you taste
can you write that ?
0
its been a while since i code in java so make an ajustment yourself if anything is wrong.
make the constructor private. it you dont have one create default constructor in private. this will make sure that no object can be created again from that class.
next follow my code below
private static ClassName instance;
public static ClassName(){
if(instance == null) instance = new ClassName();
return instance;
}
just change ClassName to your class.
to use it just call ClassName.get();