0
votes

Full Error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.MappingException: Association references unmapped class: java.util.List

Here are my Domain classes:

class File implements Serializable {

    String path;
    String name;

    public File(String path, String name) {
        this.path = path;
        this.name = name;
    }
}

class Directory extends File {

    List files = [];

    public Directory(String path, String name) {
        super(path, name);
    }
}

Here is my DirectoryService:

@Transactional
class DirectoryService {

    def fetchDirectory(String path) {
        java.io.File dir = new Path(path);
        java.io.File[] files = dir.listFiles();

        Directory pdirectory = new Directory(path, dir.getName());
        List list = [];
        for(java.io.File file : files) {
            File pfile = new File(path, file.getName());
            list.add(pfile);
        }
        pdirectory.files = list;
        return pdirectory;
    }
}

The problem occurs because I have a List files = [] in Directory model class.

I don't even understand the problem to be able to find a solution. Why does Grails not allow me to have list in models? And if it is not actually allowed, I want to know how to make it work.

In my application I have many models with datasources that are not databases; and in this case, the SQL relationship equivalent is "Directory hasMany File." Also Directory itself is a subset of File.

1
does it work if you don't initialize the list in the model?shaydel
Have you tried just using static hasMany = [files: File] instead? I think it needs to know a domain type for the collection/relationship.Todd W Crone
@shaydel no but I found a solution.Gasim
@ToddWCrone I will try it in a bit. This sounds like a much better solution. I want to understand though. How does it work if the object is derived from File?Gasim
You could probably try to be specific i.e. List<File> files = []defectus

1 Answers

1
votes

I found out that the Groovy initializes objects if there is no initialization. For example, List<File> files compiles to List<File> files = new List<File>();. So, I changed the type to LinkedList and everything worked.