126 Replies
JavaBot
JavaBot8mo ago
This post has been reserved for your question.
Hey @Danix! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Danix
DanixOP8mo ago
@dan1st | Daniel hey bro can u help me please
szatkus
szatkus8mo ago
Caused by: java.lang.NoClassDefFoundError: antlr/collections/List That's your problem.
JavaBot
JavaBot8mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
JavaBot
JavaBot8mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Danix
DanixOP7mo ago
can u please ellaborate ? @sudha9163 @dan1st | Daniel hey broo can u look 0ver it and check the error bcz i am really stuck into it .
dan1st
dan1st7mo ago
.
Danix
DanixOP7mo ago
But i remove the class and found some other error that looks like this https://sourceb.in/fNII4Iux9 @dan1st | Daniel
dan1st
dan1st7mo ago
What's the pom.xml? How do you run the application?
Danix
DanixOP7mo ago
On server
Danix
DanixOP7mo ago
Danix
DanixOP7mo ago
and here is the pom.xml ' @dan1st | Daniel
dan1st
dan1st7mo ago
I asked how, not where and you don't need to ping me
Danix
DanixOP7mo ago
How do u run the application? Means
dan1st
dan1st7mo ago
Why are you using version 5.3.20 for spring-orm as opposed to 5.3.18? How you are running the application mvn spring-boot:run? Do you deploy a WAR file?
Danix
DanixOP7mo ago
No it's not a spring boot app it's spring MVC project No
dan1st
dan1st7mo ago
So how are you doing it?
Danix
DanixOP7mo ago
I am deploy it to the tomcat server
dan1st
dan1st7mo ago
and how? Does that mean it isn't a WAR file?
Danix
DanixOP7mo ago
Basically I am adding the project to the tomcat server like this
Danix
DanixOP7mo ago
No description
dan1st
dan1st7mo ago
ok that's what I wanted to know What about that? Is there a reason for this?
Danix
DanixOP7mo ago
Like I think this is the only way to start a project in spring MVC or in Servlets?
szatkus
szatkus7mo ago
One of many 😄
Danix
DanixOP7mo ago
So is this the actual reason why the error is coming?
dan1st
dan1st7mo ago
I want to know about this this could be the reason for the error Unlikely
Danix
DanixOP7mo ago
But now I have changed it
dan1st
dan1st7mo ago
what did you change to what?
szatkus
szatkus7mo ago
No idea, it seems that you removed the error.
Danix
DanixOP7mo ago
From the version 5.3.20 to 5.3.18 of spring orm .
dan1st
dan1st7mo ago
Did that change anything? Are you getting the same error again?
Danix
DanixOP7mo ago
https://sourceb.in/SmRvywOPb7 here is the error in think it is now changed this is now how the code looks like https://sourceb.in/8OJ660Ck38
dan1st
dan1st7mo ago
ok that seems somewhat better looks like the HibernateTemplate has an issue
Danix
DanixOP7mo ago
Like how bcz i have provided it everything that it wants ...
dan1st
dan1st7mo ago
Stack Overflow
No Bean Creation when Autowiring HibernateTemplate
I am creating a Spring Application but when I am Autowiring HibernateTemplate and running my application, I am getting BeanCreationException and it could not autowire HibernateTemplate. Stack Trace...
Danix
DanixOP7mo ago
there was only one single answer
Hibernate Bean Configuration File was not loaded in Web.xml file.
Hibernate Bean Configuration File was not loaded in Web.xml file.
and i think its correct in my project
szatkus
szatkus7mo ago
I don't know if beans defined in XML are any different, but you can try adding @Qualifier("hibernateTemplate")
Danix
DanixOP7mo ago
Nahh that doesn't work
dan1st
dan1st7mo ago
Do you have a web.xml?
Danix
DanixOP7mo ago
Yehh
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">

<absolute-ordering></absolute-ordering>
<servlet>
<servlet-name>LoginPage</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dispatcherservlet.xml</param-value>
</init-param>

<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>LoginPage</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

</web-app>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">

<absolute-ordering></absolute-ordering>
<servlet>
<servlet-name>LoginPage</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dispatcherservlet.xml</param-value>
</init-param>

<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>LoginPage</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

</web-app>
dan1st
dan1st7mo ago
Do you have anything else in the WEB-INF?
Danix
DanixOP7mo ago
this is how it looks likes
No description
dan1st
dan1st7mo ago
What's the config.xml?
Danix
DanixOP7mo ago
The spring configuration
Danix
DanixOP7mo ago
dan1st
dan1st7mo ago
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config.xml</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config.xml</param-value>
</context-param>
try adding that to the web.xml
Danix
DanixOP7mo ago
https://sourceb.in/mmrrpBLKq9 i think the issue is still same
dan1st
dan1st7mo ago
that's a different error
Danix
DanixOP7mo ago
Ohh yehh
dan1st
dan1st7mo ago
Stack Overflow
"java.lang.TypeNotPresentException: Type org.hibernate.SessionFacto...
I have "java.lang.TypeNotPresentException: Type org.hibernate.SessionFactory not present " Error when trying to run spring MVC project with hibernate + tomcat on intelliJIdea. Here is my Depende...
dan1st
dan1st7mo ago
Do you have hibernate-core in your pom.xml?
Danix
DanixOP7mo ago
Yehh
dan1st
dan1st7mo ago
Can you try changing the version of hibernate-core to 5.5.4?
Danix
DanixOP7mo ago
here is the error https://sourceb.in/qRXdj4NzM8 i found
dan1st
dan1st7mo ago
actually 5.6.7.Final is probably better and 6.2.3.Final for Hibernate validator see https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-dependencies/2.6.6/spring-boot-dependencies-2.6.6.pom for versions that should match
dan1st
dan1st7mo ago
. in your pom.xml
Danix
DanixOP7mo ago
i did it but still facing the error
dan1st
dan1st7mo ago
Can you show it?
Danix
DanixOP7mo ago
Danix
DanixOP7mo ago
yeh sure
dan1st
dan1st7mo ago
Did you reload the Maven project and restart tomcat after the change?
Danix
DanixOP7mo ago
yeh alt +f5 in eclipse https://sourceb.in/sH4BqpnAM5
dan1st
dan1st7mo ago
Do you have a build directory in the project? or target What's in WEB-INF/lib?
Danix
DanixOP7mo ago
This is inside of the lib folder
No description
Danix
DanixOP7mo ago
this is what target folder have inside
No description
dan1st
dan1st7mo ago
You could try putting hibernate and other dependencies into WEB-INF/lib if you don't know how to do that, you could also get Maven to do it
Danix
DanixOP7mo ago
how to do it ?
dan1st
dan1st7mo ago
I'm currently writing the configuration for it
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.6.1</version>
<configuration>

</configuration>
<executions>
<execution>
<id>copy-libs</id>
<phase>generate-resources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.basedir}/src/main/webapp/WEB-INF/lib</outputDirectory>
<includeScope>compile</includeScope>
<includeGroupIds>org.hibernate</includeGroupIds>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.6.1</version>
<configuration>

</configuration>
<executions>
<execution>
<id>copy-libs</id>
<phase>generate-resources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.basedir}/src/main/webapp/WEB-INF/lib</outputDirectory>
<includeScope>compile</includeScope>
<includeGroupIds>org.hibernate</includeGroupIds>
</configuration>
</execution>
</executions>
</plugin>
You could try adding this to the pom.xml this should attempt to copy the hibernate stuff to WEB-INF/lib
dan1st
dan1st7mo ago
After doing that, it should look like this
No description
dan1st
dan1st7mo ago
Essentially that configures the dependency plugin (which manages dependencies) to automatically copy certain dependencies in the generate-resources phase. It is then configured to only do this for dependencies in org.hibernate with the scope compile (the default scope) and to copy it to WEB-INF/lib
Danix
DanixOP7mo ago
So when i shift to spring boot from this then should i have to do it everytime
dan1st
dan1st7mo ago
THis is normally not necessary with Spring Boot Does it fix the error?
Danix
DanixOP7mo ago
No 🙁 here is the error https://sourceb.in/sNkNTvjYmC
dan1st
dan1st7mo ago
if you change <outputDirectory>${project.basedir}/src/main/webapp/WEB-INF/lib</outputDirectory> to <outputDirectory>${project.basedir}/src/main/resources/WEB-INF/lib</outputDirectory>, it doesn't change anything, right?
dan1st
dan1st7mo ago
another thing yu could try is to right-click your project and select build path>configure build path. There, check Maven Dependencies under Order and Export
No description
No description
Danix
DanixOP7mo ago
https://sourceb.in/evukY5GBoo The error i got after doing this !
JavaBot
JavaBot7mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Danix
DanixOP7mo ago
Hey did u find why the error is coming @dan1st | Daniel
dan1st
dan1st7mo ago
tbh idk Actually what's your LoginPage? Maybe the issue is with your config.xml and maybe you could try that
dan1st
dan1st7mo ago
In the build path, go to Add Library
No description
dan1st
dan1st7mo ago
select Web App Libraries
No description
dan1st
dan1st7mo ago
make sure the right project is selected
No description
dan1st
dan1st7mo ago
and click Finish
dan1st
dan1st7mo ago
then it should look somewhat like that
No description
Danix
DanixOP7mo ago
Actually when did not connect the spring with orm then it was working fine but when I connected it with orm and try to get hibernate Template then it starts giving me errors
dan1st
dan1st7mo ago
Do you really need HibernateTemplate? I think HibernateTemplate doesn't even exist in newer Spring versions (you are using an old version of Spring)
Danix
DanixOP7mo ago
So then how to work with orm in spring? I think you are right bcz the video which I am following rn is 3 yrs old and in the comments people are also getting the same type of error as me
dan1st
dan1st7mo ago
I think its's possible to directly use SessionFactory instead of HibernateTemplate videos are a problem in general
Danix
DanixOP7mo ago
Hmm yehh u are right So now what should I have to remove from my config.xml
dan1st
dan1st7mo ago
maybe everything related to HibernateTemplate? But I think you have problems with SessionFactory, right?
Danix
DanixOP7mo ago
Yehh
dan1st
dan1st7mo ago
If you show me your current web.xml, config.xml and controller (as text, not with images or links to other sites), I may be able to reproduce it by myself
Danix
DanixOP7mo ago
Alright give me 3 min https://sourceb.in/WjYIRdSuLn here it is
dan1st
dan1st7mo ago
What's com.controllers.Database.DaoEntity?
Danix
DanixOP7mo ago
its database entity where i have made dao inteface and its implemented class and a Dao Entity which i have creted using hibernate
dan1st
dan1st7mo ago
ok so for me it works but I made some changes since you now don't have the dispatcherservlet.xml in your web.xml, I added this to the config.xml:
<bean id = "viewresolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">

<property name="prefix" value="/WEB-INF/lib/view/"></property>
<property name="suffix" value=".jsp"></property>

</bean>
<bean id = "viewresolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">

<property name="prefix" value="/WEB-INF/lib/view/"></property>
<property name="suffix" value=".jsp"></property>

</bean>
dan1st
dan1st7mo ago
also if yoou expand Web App Libraries>hibernate-core and select dialect, is there a MySQL55Dialect or MySQL8Dialect class there?
No description
Danix
DanixOP7mo ago
yehh it is here
dan1st
dan1st7mo ago
Which one is there? The thing is that I'm using a newer version of all of these things so a bit of it is different but it does work for me
Danix
DanixOP7mo ago
there are 2 of them 1st is MySQL8Dialect.class and the second one is MySQL55Dialect.class as well
dan1st
dan1st7mo ago
ok I think MySQL8Dialect is better for you so in your config.xml, also change <prop key="hibernate.dialect">org.hibernate.dialect.MySQL55Dialect</prop> to <prop key="hibernate.dialect">org.hibernate.dialect.MySQL8Dialect</prop> and you also have this in the config.xml:
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate5.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate5.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
comment this out i.e. you can replace it with
<!-- <bean id="hibernateTemplate" class="org.springframework.orm.hibernate5.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory" />
</bean>-->
<!-- <bean id="hibernateTemplate" class="org.springframework.orm.hibernate5.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory" />
</bean>-->
and it will no longer be active and after you did all that, tell me what happens
Danix
DanixOP7mo ago
so i have to change the dialect from 55 to 8 and comment this out right ?
dan1st
dan1st7mo ago
yes and don't forget about that because you have the config.xml instead of the dispatcherservlet.xml now so you still need these parts
Danix
DanixOP7mo ago
so u mean i have to add these lines to the config.xml aswell ? @dan1st | Daniel
dan1st
dan1st7mo ago
which lines?
Danix
DanixOP7mo ago
<bean id = "viewresolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">

<property name="prefix" value="/WEB-INF/lib/view/"></property>
<property name="suffix" value=".jsp"></property>

</bean>
<bean id = "viewresolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">

<property name="prefix" value="/WEB-INF/lib/view/"></property>
<property name="suffix" value=".jsp"></property>

</bean>
dan1st
dan1st7mo ago
yes if you still want to use JSP, you probably need it
Danix
DanixOP7mo ago
but i already have it in dispatcher-servlet.xml
dan1st
dan1st7mo ago
Well you no longer use that in your web.xml, right?
Danix
DanixOP7mo ago
ohh yeh i have passed the name of the config.xml file in the web.xml so now i got another error bcz i have also comment out the hibernate template bean https://sourceb.in/waPH7hhCtd @dan1st | Daniel
dan1st
dan1st7mo ago
How is that another error? Also why do you use that sourcebin site instead of just posting these things in Discord using a codeblock?
Danix
DanixOP7mo ago
Danix
DanixOP7mo ago
The config file now
dan1st
dan1st7mo ago
You still have this
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate5.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate5.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
Try commenting this out as well Also can you show the code you are using HibernateTemplate with? You likely need to change it For me, it's possible to use Hibernate somewhat like that (using SessionFactory and not HibernateTemplate):
@Controller
public class Login {

private final SessionFactory sessionFactory;

public Login(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;

}

@RequestMapping("/hi")
public String hi() {
System.out.println("Hii");
try(EntityManager em = sessionFactory.createEntityManager()){
DaoEntity entity = new DaoEntity();
entity.setId(123L);
entity.setName("test");
em.getTransaction().begin();
em.persist(entity);
em.getTransaction().commit();
}
return "hi";
}

@RequestMapping("/ho")
public String ho() {
System.out.println("Ho");
try(EntityManager em = sessionFactory.createEntityManager()){
System.out.println(em.find(DaoEntity.class, 123L).getName());
}
return "hi";
}
}
@Controller
public class Login {

private final SessionFactory sessionFactory;

public Login(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;

}

@RequestMapping("/hi")
public String hi() {
System.out.println("Hii");
try(EntityManager em = sessionFactory.createEntityManager()){
DaoEntity entity = new DaoEntity();
entity.setId(123L);
entity.setName("test");
em.getTransaction().begin();
em.persist(entity);
em.getTransaction().commit();
}
return "hi";
}

@RequestMapping("/ho")
public String ho() {
System.out.println("Ho");
try(EntityManager em = sessionFactory.createEntityManager()){
System.out.println(em.find(DaoEntity.class, 123L).getName());
}
return "hi";
}
}
btw please follow naming conventions in your code if possible: https://discord.com/channels/648956210850299986/1241797526374580325/1244581989864964109
Phloof_boll
Phloof_boll7mo ago
Naming conventions ensure that projects have similar names and allow to distinguish e.g. packages, classes and methods/variables. For that, it is important developers don't mix naming conventions. Most Java code follows these naming conventions: - Type names (e.g. classes or interfaces) should be PascalCase meaning the first letter of every word is written in uppercase while all other letters are lowercase. - Constants are ALL_UPPERCASE_SEPARATED_BY_UNDERSCORES. - Other variables (both fields and local variables) as well as methods are camelCase. This means the identifiers start with a lowercase letter, all subsequent words start with an uppercase letter and all other letters are lowercase. - Package names are all_lowercase whereas dots are used to create a hierarchy of packages. All packages of an application are typically grouped together in some top level package. This typically uses reverse domain name notation. For example, an application called MyApplication maintained by a company/individual owning the domain example.com would put all its classes in a package named com.example.myapplication or subpackages.
package com.mydomain.myproject.somesubpackage;

public class ClassNamesArePascalCase{
private static final String CONSTANTS_ARE_UPPER_CASE = "Hello World";
private int variablesAreCamelCase = 13;

public void methodNamesAreCamelCase(){
int localVariablesAreAlsoCamelCase = 37;
}
}
package com.mydomain.myproject.somesubpackage;

public class ClassNamesArePascalCase{
private static final String CONSTANTS_ARE_UPPER_CASE = "Hello World";
private int variablesAreCamelCase = 13;

public void methodNamesAreCamelCase(){
int localVariablesAreAlsoCamelCase = 37;
}
}
There are other naming conventions as well (for example prepending getters with get and setters with set, e.g. getMyVariable/setMyVariable. Aside from that, projects may have specific naming conventions.
Danix
DanixOP7mo ago
package com.controllers.Database;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.stereotype.Repository;


@Repository
public class DaoEntityImp implements Dao {


@Autowired
private HibernateTemplate hibernateTemplate;

@Transactional
@Override
public int saveUser(DaoEntity daoEntity) {

return (int) this.hibernateTemplate.save(daoEntity);
}

@Override
public DaoEntity getUser(int userId) {
DaoEntity daoEntity = this.hibernateTemplate.get(DaoEntity.class, userId);
return daoEntity;
}

@Override
public int deleteUser(int userId) {
// TODO Auto-generated method stub
return 0;
}







}
package com.controllers.Database;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.stereotype.Repository;


@Repository
public class DaoEntityImp implements Dao {


@Autowired
private HibernateTemplate hibernateTemplate;

@Transactional
@Override
public int saveUser(DaoEntity daoEntity) {

return (int) this.hibernateTemplate.save(daoEntity);
}

@Override
public DaoEntity getUser(int userId) {
DaoEntity daoEntity = this.hibernateTemplate.get(DaoEntity.class, userId);
return daoEntity;
}

@Override
public int deleteUser(int userId) {
// TODO Auto-generated method stub
return 0;
}







}
here is the class where i am using the Hibernate Template
dan1st
dan1st7mo ago
try it like this:
package com.controllers.Database;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.stereotype.Repository;


@Repository
public class DaoEntityImp implements Dao {


private final EntityManager entityManager;//I CHANGED THIS

public DaoEntityImp(SessionFactory sessionFactory) {//I ADDED THIS CONSTRUCTOR
this.entityManager = sessionFactory.createEntityManager();
}

@Override
public int saveUser(DaoEntity daoEntity) {
this.entityManager.getTransaction().begin();//these things are instead of @Transaction, there is a better way but this way should definitely work
try{
this.entityManager.persist(daoEntity);
this.entityManager.getTransaction().commit();
return 1;//no idea what you actually want to return here
} catch(RuntimeException e) {
this.entityManager.getTransaction().rollback();
throw e;
}
}

@Override
public DaoEntity getUser(int userId) {
DaoEntity daoEntity = this.entityManager.get(DaoEntity.class, userId);
return daoEntity;
}

@Override
public int deleteUser(int userId) {
// TODO Auto-generated method stub
return 0;
}
}
package com.controllers.Database;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.stereotype.Repository;


@Repository
public class DaoEntityImp implements Dao {


private final EntityManager entityManager;//I CHANGED THIS

public DaoEntityImp(SessionFactory sessionFactory) {//I ADDED THIS CONSTRUCTOR
this.entityManager = sessionFactory.createEntityManager();
}

@Override
public int saveUser(DaoEntity daoEntity) {
this.entityManager.getTransaction().begin();//these things are instead of @Transaction, there is a better way but this way should definitely work
try{
this.entityManager.persist(daoEntity);
this.entityManager.getTransaction().commit();
return 1;//no idea what you actually want to return here
} catch(RuntimeException e) {
this.entityManager.getTransaction().rollback();
throw e;
}
}

@Override
public DaoEntity getUser(int userId) {
DaoEntity daoEntity = this.entityManager.get(DaoEntity.class, userId);
return daoEntity;
}

@Override
public int deleteUser(int userId) {
// TODO Auto-generated method stub
return 0;
}
}
Alternatively you could replace the constructor with
public Login(EntityManagerFactory emf) {
this.entityManager = emf.createEntityManager();
}
public Login(EntityManagerFactory emf) {
this.entityManager = emf.createEntityManager();
}
Alternatively if you want to use @Transactional, you could try this:
@Repository
public class DaoEntityImp implements Dao {


private final SessionFactory sesionFactory;//I CHANGED THIS

public DaoEntityImp(SessionFactory sessionFactory) {//I ADDED THIS CONSTRUCTOR
this.sessionFactory = sessionFactory;
}

@Transactional
@Override
public int saveUser(DaoEntity daoEntity) {
this.sessionFactory.getCurrentSession().save(daoEntity);
return 1;//idk what you want to return here
}

@Override
public DaoEntity getUser(int userId) {
DaoEntity daoEntity = this.sessionFactory.getCurrentSession().get(DaoEntity.class, userId);
return daoEntity;
}

@Override
public int deleteUser(int userId) {
// TODO Auto-generated method stub
return 0;
}
}
@Repository
public class DaoEntityImp implements Dao {


private final SessionFactory sesionFactory;//I CHANGED THIS

public DaoEntityImp(SessionFactory sessionFactory) {//I ADDED THIS CONSTRUCTOR
this.sessionFactory = sessionFactory;
}

@Transactional
@Override
public int saveUser(DaoEntity daoEntity) {
this.sessionFactory.getCurrentSession().save(daoEntity);
return 1;//idk what you want to return here
}

@Override
public DaoEntity getUser(int userId) {
DaoEntity daoEntity = this.sessionFactory.getCurrentSession().get(DaoEntity.class, userId);
return daoEntity;
}

@Override
public int deleteUser(int userId) {
// TODO Auto-generated method stub
return 0;
}
}
Danix
DanixOP7mo ago
Ok I will try it later after reaching my home But can you tell me please bro can I skip the spring MVC project bcz like I have completed the basics annotation and basic understanding of spring MVC so can I go for spring boot directly or stayed with it and make projects ?
dan1st
dan1st7mo ago
yeah sure
Danix
DanixOP7mo ago
Does it effect anything in my future ?
dan1st
dan1st7mo ago
What specifically? In most cases, Spring is used with Spring Boot and tbh I've never used Spring without Spring Boot but as you have probably seen, I understand how it works enough so I can probably fix most problems (if I encounter a problem, I am more likely to properly understand it than when someone else encounters it because if it's on my machine, I can easily reproduce it and it's also something important for me so I'm willing to spend time on it) So essentially I don't think you need to know how to use everything with Spring without Spring Boot but it's good to understand how these things work
Danix
DanixOP7mo ago
So directly jumping into spring boot now will not be the bad decision for me .. And the main reason I am thinking to directly switch to spring boot is bcz i have completed spring core , spring MVC basics , spring with orm so I think this is enough to jump to spring boot right? Does it important to learn spring JDBC Module as well ?
dan1st
dan1st7mo ago
You can also use Spring JDBC with Spring Boot
JavaBot
JavaBot7mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server