I've been going thru a lot of docs and posts here and other places and have not found a solution to my problem.
When I build my spring boot / jpa / hibernate / maven project, the metamodel classes are generated in the target/generated-sources folder, but as per the jboss docs, when I set my java compiler -> annotation processing to generate metamodel classes in target/metamodel, no classes are generated, therefor my controller class is not able to access any of the Widget_
fields.
the relevant pom info is here:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>5.3.10.Final</version><!--$NO-MVN-MAN-VER$-->
<scope>provided</scope>
</dependency>
<build>
<finalName>SpringBootWebAppTest</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>10</source>
<target>10</target>
<compilerArguments>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
</compilerArguments>
</configuration>
</plugin>
</plugins>
</build>
I have organized my classes along the lines of this stackoverflow q
@Entity
@Table(name = "widget")
@EntityListeners(AuditingEntityListener.class)
@JsonIgnoreProperties(value = {"created", "lastEdited"}, allowGetters = true)
public class Widget {
@Id
@GeneratedValue (strategy = GenerationType.AUTO)
private Long id;
@NotNull(message = "name is required")
private String name;
@NotNull(message = "sku is required")
private long sku;
with a repository:
@Repository
public interface WidgetRepository extends JpaRepository<Widget, Long> {
}
a custom repository
public interface CustomWidgetRepository {
public List<Widget> getWidgetsMatchingName(String searchText);
}
and an impl:
@Service
public class CustomWidgetRepositoryImpl implements CustomWidgetRepository {
@PersistenceContext
EntityManager entityManager;
@Override
public List<Widget> getWidgetsMatchingName(String searchText) {
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<Widget> query = criteriaBuilder.createQuery(Widget.class);
Root<Widget> widgetRoot = query.from(Widget.class);
// this doesn't compile, as metamodel classes are not created where they can be accessed
// query.where(criteriaBuilder.like(widgetRoot.get(Widget_.), "%" + searchText + "%"));
query.select(widgetRoot);
return entityManager.createQuery(query).getResultList();
}
}
according to this q (scroll down to march 2018 answer), just setting the compilier->annotation settings in eclipse should be enough. I came across a couple of resources, such as this one that describes how to add the target/generated-sources/annotations to the classpath, but not sure how old that post is, and wondering if it conflicts with the first link that says just to update the compiler->annotation settings.
I asked a related question with regards to metamodel classes, but that project did not use spring boot, and this current project is just a super simple test project to get spring boot jpa stuff running so I can migrate my main project over.
thanks for any help.
Update
It was this maven plugin that adds to target/generated-sources/annotations as a src folder that did the trick.