java - Could not initialize proxy - no Session spring boot and javafx -
i'm using spring boot , javafx.
yesterday found https://github.com/thomasdarimont/spring-labs/tree/master/spring-boot-javafx , add spring jpa pom.xml , configuration application.properties.
pom
<dependencies> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter</artifactid> </dependency> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-test</artifactid> <scope>test</scope> </dependency> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-jdbc</artifactid> </dependency> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-data-jpa</artifactid> </dependency> <dependency> <groupid>mysql</groupid> <artifactid>mysql-connector-java</artifactid> <version>5.1.18</version> </dependency> </dependencies>
application.properties
app.ui.title=spring boot java fx hello world spring.datasource.url = jdbc:mysql://mysql0.xxx/3450_ps15\?useunicode=true&characterencoding=utf-8 spring.datasource.username = xxx spring.datasource.password = xxx spring.datasource.driverclassname = com.mysql.jdbc.driver spring.datasource.testonborrow=true spring.datasource.validationquery=select 1 spring.jpa.show-sql=true spring.jpa.hibernate.ddl-auto=none
i spend many hours trying fix error. on entity must use fetchtype.eager
otherwise error. have 3600 records taking db take many houres in eager. trying add @transactional(readonly=true)
in service implementation , repository. code, maybe forgot something. service
public interface productservice { page<productps> findall(pageable pageable); list<productps> findall(); long getcount(); }
repository
@transactional public interface productrepository extends repository<productps, long>{ @transactional @query("select p productps p inner join p.productlang lang lang.lang.id=1") page<productps> findall(pageable pageable); @query("select p productps p inner join p.productlang lang lang.lang.id=1") list<productps> findall(); long count(); }
service implementation
@component @transactional(readonly=true) @service public class productserviceimp implements productservice{ @autowired private productrepository productrepository; @autowired public productserviceimp(productrepository productrepository) { this.productrepository = productrepository; } @override @transactional(readonly=true) public page<productps> findall(pageable pageable) { if (!transactionsynchronizationmanager.isactualtransactionactive()) { throw new illegalstateexception("no active transaction!!!!"); } return productrepository.findall(pageable); } @override @transactional(readonly=true) public list<productps> findall() { // todo auto-generated method stub return productrepository.findall(); } @override @transactional public long getcount() { // todo auto-generated method stub return productrepository.count(); } }
and entity
private static final long serialversionuid = -1804619891680745433l; @id @generatedvalue @column(name="id_product") private long id; @column(name="id_category_default") private int idcategorydefault; private float price; private string reference; @onetomany(mappedby = "product") private list<stockps> stock; @onetomany(fetch = fetchtype.lazy,mappedby = "produkt") private list<productlangps> productlang;
i'm using hibernate.enable_lazy_load_no_trans
take records , when scroll in tableview take next take many time. i've added
@enabletransactionmanagement
in config , transaction working doesn't not me. bug or miss something? possible set session manually in spring data? if on use pagination try
private node createpage(int pageindex) { int fromindex = pageindex * 50; int toindex = (int) math.min(fromindex + 50, productservice.getcount()); pageable topten = new pagerequest(fromindex, toindex); table.setitems(fxcollections.observablearraylist(productservice.findall(topten).getcontent())); return table; }
on next page return no records. return 0 n.
Comments
Post a Comment