We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
package com.ayush.jpa.JpaDemo;
import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication public class JpaDemoApplication implements CommandLineRunner {
private Logger logger = LoggerFactory.getLogger(JpaDemoApplication.class); @Autowired private PersonRepository repo; public static void main(String[] args) { SpringApplication.run(JpaDemoApplication.class, args); } @Override public void run(String... args) throws Exception { // TODO Auto-generated method stub logger.info("Person findById----", repo.findById(10002)); }
}
import java.util.Date;
import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id;
@entity public class Person {
@Id @GeneratedValue private int id; private String name; private String location; private Date birthDate; public Person() { } public Person(int id, String name, String location, Date birthDate) { super(); this.id = id; this.name = name; this.location = location; this.birthDate = birthDate; } public Person(String name, String location, Date birthDate) { super(); this.name = name; this.location = location; this.birthDate = birthDate; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getLocation() { return location; } public void setLocation(String location) { this.location = location; } public Date getBirthDate() { return birthDate; } public void setBirthDate(Date birthDate) { this.birthDate = birthDate; } @Override public String toString() { return String.format("\nPerson [id=%s, name=%s, location=%s, birthDate=%s]", id, name, location, birthDate); }
import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import javax.transaction.Transactional;
import org.springframework.stereotype.Repository;
@repository @transactional public class PersonRepository {
@PersistenceContext EntityManager manager; public Person findById(int id) { return manager.find(Person.class, id); }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
package com.ayush.jpa.JpaDemo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class JpaDemoApplication implements CommandLineRunner {
}
package com.ayush.jpa.JpaDemo;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@entity
public class Person {
}
package com.ayush.jpa.JpaDemo;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.transaction.Transactional;
import org.springframework.stereotype.Repository;
@repository
@transactional
public class PersonRepository {
}
The text was updated successfully, but these errors were encountered: