I have the following java class:
package domain;
//imports
@Entity
public class User {
@Id @GeneratedValue
private long id;
private String name;
private String password;
private String mail;
//Getters, Setters and Constructors
}
When I change the file extension to .groovy, the application stops working. In fact it throws this stacktrace:
org.springframework.dao.InvalidDataAccessApiUsageException:
Unknown entity: domain.User; nested
exception is
java.lang.IllegalArgumentException:
Unknown entity: domain.User
I’m reading this book and the author states that any groovy class can take the place of a java class just changing its extension. So why does spring and JPA don’t recognize my groovy class?
Has anyone used this technologies successfully?
There’s not a lot of info here, so time to guess.
Seems like Spring can’t find the User.class file. The Groovy and Java compilers may have different output paths, and the Groovy output path may not be in your classpath, or your deployment set.
Check your War, is User.class in it? Is it in WEB-INF/classes/domain? If not, then the Groovy output folder doesn’t seem to be in your deployment. Try changing the Groovy output folder to match your Java output folder.