JPArepository - Łączenie trzech Tabel z wykorzystaniem JOIN

Odpowiedz Nowy wątek
2019-08-09 22:58
0

Witam

Mam problem z zapytaniem @Query z wykorzystaniem Join
Do rzeczy:
Takie zapytanie :
@Query("SELECT new pl.tabele.feature.product.DTO.ProductDetailsDTO(c.customerId, c.name, p.unit, p.price, od.quantity, sum(p.price * od.quantity)) " +
"FROM Customer c, Product p, Orders o, OrderDetails od " +
"WHERE c.customerId = :id " +
"AND c.customerId = o.customerId " +
"AND p.productId = od.productId " +
"AND o.orderId = od.orderId " +
"GROUP BY c.customerId, c.name, c.contactName, c.city, c.country, " +
"p.productId, p.name, p.unit, p.price, od.quantity")

List<productdetailsdto> findProductDetailsList(@Param("id") Long id);

To zapytanie działa pięknie zwraca mi Liste ProductDetailsDTO

Ale chciałem stworzyć to samo zapytanie z wykorzystaniem funkcji JOIN
I niestety nie umiem sobie z tym poradzić ponieważ :

@Query("SELECT new pl.tabele.feature.product.DTO.ProductDetailsDTO(c.customerId, c.name, product.unit, product.price, orderDetails.quantity, sum(product.price orderDetails.quantity)) " +
"FROM Customer c " +
"JOIN c.customerId orders " +
"JOIN product.productId orderDetails " +
"JOIN orders.orderId orderDetails " +
"WHERE c.customerId = :id " +
"GROUP BY c.customerId, c.name, c.contactName, c.city, c.country, " +
"product.productId, product.name, product.unit, product.price, orderDetails.quantity, (product.price
orderDetails.quantity)")

List<ProductDetailsDTO> findProductDetailsList(@Param("id") Long id);

Takie zapytanie zwraca mi błąd:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'customerController' defined in file [D:\Projekty\3\tabele\target\classes\pl\tabele\controller\CustomerController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'customerService' defined in file [D:\Projekty\3\tabele\target\classes\pl\tabele\feature\customer\service\CustomerService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customerRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List pl.tabele.feature.customer.repository.CustomerRepository.findProductDetailsList(java.lang.Long)!
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:780) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:219) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1346) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1192) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:870) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877) ~[spring-context-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.2.0.M4.jar:2.2.0.M4]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:748) ~[spring-boot-2.2.0.M4.jar:2.2.0.M4]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395) ~[spring-boot-2.2.0.M4.jar:2.2.0.M4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) ~[spring-boot-2.2.0.M4.jar:2.2.0.M4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1227) ~[spring-boot-2.2.0.M4.jar:2.2.0.M4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1216) ~[spring-boot-2.2.0.M4.jar:2.2.0.M4]
at pl.tabele.TabeleApplication.main(TabeleApplication.java:10) ~[classes/:na]
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'customerService' defined in file [D:\Projekty\3\tabele\target\classes\pl\tabele\feature\customer\service\CustomerService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customerRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List pl.tabele.feature.customer.repository.CustomerRepository.findProductDetailsList(java.lang.Long)!
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:780) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:219) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1346) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1192) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1276) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1196) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:868) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:771) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
... 19 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customerRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List pl.tabele.feature.customer.repository.CustomerRepository.findProductDetailsList(java.lang.Long)!
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1791) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1276) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1196) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:868) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:771) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
... 33 common frames omitted
Caused by: java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List pl.tabele.feature.customer.repository.CustomerRepository.findProductDetailsList(java.lang.Long)!
at org.springframework.data.jpa.repository.query.SimpleJpaQuery.validateQuery(SimpleJpaQuery.java:93) ~[spring-data-jpa-2.2.0.RC1.jar:2.2.0.RC1]
at org.springframework.data.jpa.repository.query.SimpleJpaQuery.<init>(SimpleJpaQuery.java:63) ~[spring-data-jpa-2.2.0.RC1.jar:2.2.0.RC1]
at org.springframework.data.jpa.repository.query.JpaQueryFactory.fromMethodWithQueryString(JpaQueryFactory.java:76) ~[spring-data-jpa-2.2.0.RC1.jar:2.2.0.RC1]
at org.springframework.data.jpa.repository.query.JpaQueryFactory.fromQueryAnnotation(JpaQueryFactory.java:56) ~[spring-data-jpa-2.2.0.RC1.jar:2.2.0.RC1]
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$DeclaredQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:142) ~[spring-data-jpa-2.2.0.RC1.jar:2.2.0.RC1]
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:209) ~[spring-data-jpa-2.2.0.RC1.jar:2.2.0.RC1]
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:79) ~[spring-data-jpa-2.2.0.RC1.jar:2.2.0.RC1]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lookupQuery(RepositoryFactorySupport.java:563) ~[spring-data-commons-2.2.0.RC1.jar:2.2.0.RC1]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$mapMethodsToQuery$1(RepositoryFactorySupport.java:556) ~[spring-data-commons-2.2.0.RC1.jar:2.2.0.RC1]
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195) ~[na:na]
at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133) ~[na:na]
at java.base/java.util.Collections$UnmodifiableCollection$1.forEachRemaining(Collections.java:1052) ~[na:na]
at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801) ~[na:na]
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484) ~[na:na]
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) ~[na:na]
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913) ~[na:na]
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:na]
at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578) ~[na:na]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.mapMethodsToQuery(RepositoryFactorySupport.java:558) ~[spring-data-commons-2.2.0.RC1.jar:2.2.0.RC1]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$new$0(RepositoryFactorySupport.java:548) ~[spring-data-commons-2.2.0.RC1.jar:2.2.0.RC1]
at java.base/java.util.Optional.map(Optional.java:265) ~[na:na]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:548) ~[spring-data-commons-2.2.0.RC1.jar:2.2.0.RC1]
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:321) ~[spring-data-commons-2.2.0.RC1.jar:2.2.0.RC1]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$5(RepositoryFactoryBeanSupport.java:297) ~[spring-data-commons-2.2.0.RC1.jar:2.2.0.RC1]
at org.springframework.data.util.Lazy.getNullable(Lazy.java:211) ~[spring-data-commons-2.2.0.RC1.jar:2.2.0.RC1]
at org.springframework.data.util.Lazy.get(Lazy.java:94) ~[spring-data-commons-2.2.0.RC1.jar:2.2.0.RC1]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:300) ~[spring-data-commons-2.2.0.RC1.jar:2.2.0.RC1]
at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:121) ~[spring-data-jpa-2.2.0.RC1.jar:2.2.0.RC1]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1850) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1787) ~[spring-beans-5.2.0.M3.jar:5.2.0.M3]
... 44 common frames omitted
Caused by: java.lang.NullPointerException: null
at org.hibernate.hql.internal.ast.HqlSqlWalker.createFromJoinElement(HqlSqlWalker.java:429) ~[hibernate-core-5.4.3.Final.jar:5.4.3.Final]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.joinElement(HqlSqlBaseWalker.java:3920) ~[hibernate-core-5.4.3.Final.jar:5.4.3.Final]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3706) ~[hibernate-core-5.4.3.Final.jar:5.4.3.Final]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3584) ~[hibernate-core-5.4.3.Final.jar:5.4.3.Final]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:720) ~[hibernate-core-5.4.3.Final.jar:5.4.3.Final]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:576) ~[hibernate-core-5.4.3.Final.jar:5.4.3.Final]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:313) ~[hibernate-core-5.4.3.Final.jar:5.4.3.Final]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:261) ~[hibernate-core-5.4.3.Final.jar:5.4.3.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:272) ~[hibernate-core-5.4.3.Final.jar:5.4.3.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:192) ~[hibernate-core-5.4.3.Final.jar:5.4.3.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:144) ~[hibernate-core-5.4.3.Final.jar:5.4.3.Final]
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:113) ~[hibernate-core-5.4.3.Final.jar:5.4.3.Final]
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:73) ~[hibernate-core-5.4.3.Final.jar:5.4.3.Final]
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:158) ~[hibernate-core-5.4.3.Final.jar:5.4.3.Final]
at org.hibernate.internal.AbstractSharedSessionContract.getQueryPlan(AbstractSharedSessionContract.java:611) ~[hibernate-core-5.4.3.Final.jar:5.4.3.Final]
at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:720) ~[hibernate-core-5.4.3.Final.jar:5.4.3.Final]
at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:104) ~[hibernate-core-5.4.3.Final.jar:5.4.3.Final]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:567) ~[na:na]
at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:350) ~[spring-orm-5.2.0.M3.jar:5.2.0.M3]
at com.sun.proxy.$Proxy91.createQuery(Unknown Source) ~[na:na]
at org.springframework.data.jpa.repository.query.SimpleJpaQuery.validateQuery(SimpleJpaQuery.java:87) ~[spring-data-jpa-2.2.0.RC1.jar:2.2.0.RC1]
... 73 common frames omitted

Nie umiem sobie z tym poradzić,
Bardzo proszę o pomoc...

Poniżej kod tych encji:

@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@Entity
public class Customer {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long customerId;
@NotNull @Length(min = 3)
private String name;
@NotNull @Length(min = 3)
private String contactName;
private String address;
@NotNull @Length (min = 3)
private String city;
private String postalCode;
@NotNull @Length (min = 3)
private String country;
@OneToMany (mappedBy = "customerId")
private List<orders> ordersList;

public Customer(Long customerId, String name, String contactName,  String city, String country) {
    this.customerId = customerId;
    this.name = name;
    this.contactName = contactName;
    this.city = city;
    this.country = country;

@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@Entity
@Table
public class Orders {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long orderId;
@NotNull
private Long customerId;
@NotNull
private Long employeeId;
@NotNull
private LocalDate orderDate;
private Long shipperId;
@ManyToOne
private Customer customers;
@OneToMany (mappedBy = "orderId" )
private List<orderdetails> orderDetails;
@ManyToOne
private Employess employee;
@ManyToOne
private Shippers shipper;

@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@Entity
public class OrderDetails {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long orderDetailId;
@NotNull
private Long orderId;
@NotNull
private Long productId;
@NotNull
private Long quantity;
@ManyToOne
private Orders orders;
@ManyToOne
private Product product;

@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@Entity
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long productId;
@NotNull
private String name;
@NotNull
private Long supplierId;
@NotNull
private Long categoryId;
@NotNull
private String unit;
@NotNull
private Double price;
@ManyToOne
private Suppliers supplier;
@ManyToOne
private Categories categories;
@OneToMany (mappedBy = "productId")
private List<orderdetails> orderDetails;

edytowany 1x, ostatnio: Qles, 2019-08-10 09:28
Wklej kod tych encji - bames 2019-08-09 23:13

Pozostało 580 znaków

2019-08-10 09:52
0

Wklejone;)

Plis, sformatuj jeszcze ten kod, łatwiej się czyta :) - Belka 2019-08-10 12:52

Pozostało 580 znaków

2019-08-10 13:26
0

W JPA/Hibernate nie da się zrobić joina po wielu listach, z tego co pamiętam. To może być to.

Pozostało 580 znaków

Odpowiedz
Liczba odpowiedzi na stronę

1 użytkowników online, w tym zalogowanych: 0, gości: 1, botów: 0