New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with Hibernate DomainExporter and persistent field declared in superclasses #235

Closed
mirkosertic opened this Issue Sep 20, 2012 · 12 comments

Comments

Projects
None yet
2 participants
@mirkosertic

There is a problem that EntitySerializer cannot correctly handle types with persistent properties from superclasses which itself are not managed by hibernate.

Exception:

14:54:28,588 ERROR ydsl.MyHibernateDomainExporter - Error creating class for ch.bedag.gba.capitastra.model.beschreibung.Teilgrundstueck
java.lang.IllegalStateException: No entity type for ch.bedag.gba.capitastra.model.EffectivityBusinessClass
at com.mysema.query.codegen.EntitySerializer.initEntityFields(EntitySerializer.java:250)
at com.mysema.query.codegen.EntitySerializer.constructors(EntitySerializer.java:177)
at com.mysema.query.codegen.EntitySerializer.serialize(EntitySerializer.java:582)

Create a superclass with properties. This class it not persistent. Declare a subclass, where theproperties from the superclass are mapped via xml mapping files. This causes the above mentioned error.

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Sep 20, 2012

Member

Could you provide an example?

Member

timowest commented Sep 20, 2012

Could you provide an example?

@mirkosertic

This comment has been minimized.

Show comment
Hide comment
@mirkosertic

mirkosertic Sep 21, 2012

As written above:

Create a superclass with properties. This class it not persistent. Declare a subclass, where the properties from the superclass are mapped via xml mapping files. This causes the above mentioned error.

As written above:

Create a superclass with properties. This class it not persistent. Declare a subclass, where the properties from the superclass are mapped via xml mapping files. This causes the above mentioned error.

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Sep 21, 2012

Member

I tried this

public class A {
    String property1;    
}

public class B extends A {    
    Long id;
    String property2;
}

and

<class name="B" table="B">
  <id access="field" name="id" type="int" column="B_ID" length="4">
     <generator class="sequence"><param name="sequence">b_id_seq</param></generator>
  </id>
  <property name="property1" column="property1" not-null="true" />
  <property name="property2" column="property2" not-null="true" />
</class>

No exception. Could you provide example domain classes and a hbm xml file? Otherwise it's only guessing from my side.

Member

timowest commented Sep 21, 2012

I tried this

public class A {
    String property1;    
}

public class B extends A {    
    Long id;
    String property2;
}

and

<class name="B" table="B">
  <id access="field" name="id" type="int" column="B_ID" length="4">
     <generator class="sequence"><param name="sequence">b_id_seq</param></generator>
  </id>
  <property name="property1" column="property1" not-null="true" />
  <property name="property2" column="property2" not-null="true" />
</class>

No exception. Could you provide example domain classes and a hbm xml file? Otherwise it's only guessing from my side.

timowest added a commit that referenced this issue Sep 21, 2012

@mirkosertic

This comment has been minimized.

Show comment
Hide comment
@mirkosertic

mirkosertic Sep 24, 2012

Hi there

I tried to track down the problem with the current snapshot version from repository, but unfortunatly i did't manage to compile it due to too many missing artifacts, like oracle drivers and other strange stuff from springsource repository.

Couln't you provide a compiled snapshot version somewhere, so it would be easier to "test" the current development builds without the pain of setting of a build environment?

Regards
Mirko

Hi there

I tried to track down the problem with the current snapshot version from repository, but unfortunatly i did't manage to compile it due to too many missing artifacts, like oracle drivers and other strange stuff from springsource repository.

Couln't you provide a compiled snapshot version somewhere, so it would be easier to "test" the current development builds without the pain of setting of a build environment?

Regards
Mirko

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Sep 24, 2012

Member

Sorry, I didn't have the time to automate snapshots. I removed the repository sections since we switched to Sonatype for Maven artifact distribution and they require that repository elements aren't used.

They are though available if you build with the jenkins profile. Just build without the tests and you are good to go.

Member

timowest commented Sep 24, 2012

Sorry, I didn't have the time to automate snapshots. I removed the repository sections since we switched to Sonatype for Maven artifact distribution and they require that repository elements aren't used.

They are though available if you build with the jenkins profile. Just build without the tests and you are good to go.

@mirkosertic

This comment has been minimized.

Show comment
Hide comment
@mirkosertic

mirkosertic Sep 24, 2012

Here are some from my point of view problematic examples:

public abstract class EigentumPersonRechtsgueltig {
    private String id;
}

public class EigentumPersonRechtsgueltigSnapshot extends EigentumPersonRechtsgueltig {
}

Class EigentumPersonRechtsgueltig is not persistent, only class EigentumPersonRechtsgueltigSnapshot. Here is an except of the mapping file:

<class name="EigentumPersonRechtsgueltigSnapshot" table="EigentumPersonRechtsgueltigSS" mutable="false">

<id name="id" type="string" length="40"/>
</class>

It seems as in EntitySerializer.java initEntityFields() an IllegalStateException is thrown because there is no EntityType available for the superType.

For EntityType EigentumPersonRechtsgueltigSnapshot the SuperType is EigentumPersonRechtsgueltig. But EigentumPersonRechtsgueltig does not have an entityType(entityType == null). Why do you make a difference here between EntityType and SuperType?

Here are some from my point of view problematic examples:

public abstract class EigentumPersonRechtsgueltig {
    private String id;
}

public class EigentumPersonRechtsgueltigSnapshot extends EigentumPersonRechtsgueltig {
}

Class EigentumPersonRechtsgueltig is not persistent, only class EigentumPersonRechtsgueltigSnapshot. Here is an except of the mapping file:

<class name="EigentumPersonRechtsgueltigSnapshot" table="EigentumPersonRechtsgueltigSS" mutable="false">

<id name="id" type="string" length="40"/>
</class>

It seems as in EntitySerializer.java initEntityFields() an IllegalStateException is thrown because there is no EntityType available for the superType.

For EntityType EigentumPersonRechtsgueltigSnapshot the SuperType is EigentumPersonRechtsgueltig. But EigentumPersonRechtsgueltig does not have an entityType(entityType == null). Why do you make a difference here between EntityType and SuperType?

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Sep 25, 2012

Member

Supertypes are added via post processing run, that's why there is a separate wrapper class for supertype referenes with the type from the first run and the entity type from the second.

I will look what went wrong here.

Member

timowest commented Sep 25, 2012

Supertypes are added via post processing run, that's why there is a separate wrapper class for supertype referenes with the type from the first run and the entity type from the second.

I will look what went wrong here.

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Sep 25, 2012

Member

Does the new example really throw an Exception? I couldn't reproduce it.

Member

timowest commented Sep 25, 2012

Does the new example really throw an Exception? I couldn't reproduce it.

timowest added a commit that referenced this issue Sep 25, 2012

@mirkosertic

This comment has been minimized.

Show comment
Hide comment
@mirkosertic

mirkosertic Sep 25, 2012

I tried the following fix and it seems to work in EntitySerializer.java:

    protected void initEntityFields(CodeWriter writer, SerializerConfig config,
                                    EntityType model) throws IOException {
        Supertype superType = model.getSuperType();
        if (superType != null && superType.getEntityType() != null && superType.getEntityType().hasEntityFields()) {
            Type superQueryType = typeMappings.getPathType(superType.getEntityType(), model, false);
            writer.line("this._super = new " + writer.getRawName(superQueryType) + "(type, metadata, inits);");
        }

        for (Property field : model.getProperties()) {
            if (field.getType().getCategory() == TypeCategory.ENTITY) {
                initEntityField(writer, config, model, field);

            } else if (field.isInherited() && superType != null && superType.getEntityType().hasEntityFields()) {
                writer.line("this.", field.getEscapedName(), " = _super.", field.getEscapedName(), SEMICOLON);
            }
        }
    }

I tried the following fix and it seems to work in EntitySerializer.java:

    protected void initEntityFields(CodeWriter writer, SerializerConfig config,
                                    EntityType model) throws IOException {
        Supertype superType = model.getSuperType();
        if (superType != null && superType.getEntityType() != null && superType.getEntityType().hasEntityFields()) {
            Type superQueryType = typeMappings.getPathType(superType.getEntityType(), model, false);
            writer.line("this._super = new " + writer.getRawName(superQueryType) + "(type, metadata, inits);");
        }

        for (Property field : model.getProperties()) {
            if (field.getType().getCategory() == TypeCategory.ENTITY) {
                initEntityField(writer, config, model, field);

            } else if (field.isInherited() && superType != null && superType.getEntityType().hasEntityFields()) {
                writer.line("this.", field.getEscapedName(), " = _super.", field.getEscapedName(), SEMICOLON);
            }
        }
    }
@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Sep 25, 2012

Member

I still need a failing example. Also which Querydsl version are you using if the examples you gave cause errors in your environment?

Member

timowest commented Sep 25, 2012

I still need a failing example. Also which Querydsl version are you using if the examples you gave cause errors in your environment?

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Sep 26, 2012

Member

I finally found a failing example and fixed the issue. The issue doesn't occur if the subtype has only non-entity properties.

Member

timowest commented Sep 26, 2012

I finally found a failing example and fixed the issue. The issue doesn't occur if the subtype has only non-entity properties.

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Sep 29, 2012

Member

Released in 2.8.0

Member

timowest commented Sep 29, 2012

Released in 2.8.0

@timowest timowest closed this Sep 29, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment