Conflicting persistence.xml in multi-module project

1,518 views
Skip to first unread message

Holger Berndt

unread,
Jul 4, 2014, 3:05:54 AM7/4/14
to sculptor...@googlegroups.com

Hi,

I'm new to sculptor and I think, it is great.I tried to setup a multi-module project. On e module is the business-tier. It works fine and all tests are running. The presentation-tier was generated perfectly. But when I start jetty a conflicting persistence.xml is found. What is the best way. Should I delete the persistence.xml from the business-tier (only test is needed), or is there another way.

Thanks for help.

Holger

Torsten Juergeleit

unread,
Jul 4, 2014, 8:24:50 PM7/4/14
to sculptor...@googlegroups.com
Hi Holger,

welcome to the Sculptor forum.

I assume you're referring to the multi-module project described in Sculptors archetype tutorial. Is this correct?

Here you should end up with two persistence xml files in the business-tier module only - one packaged with the jar (src/generated/resources/META-INF/persistence.xml) and one is used for unit tests only (src/test/generated/resources/META-INF/persistence-test.xml). These are the only persistence xml files I'm aware of.

The web-tier should not contain any business-tier stuff like persistence xml - only web-related stuff like REST code (if any). Please make sure that "src/main/resources/generator/sculptor-generator.properties" does contain the proper project nature of "presentation-tier". Without the setting "project.nature" the default project nature "business-tier" is used. Then you will end up with generated stuff which belongs to the business-tier module.

At the end of the day the generator properties have to be configured properly within both modules (business tier and web-tier). Otherwise invalid stuff will be generated.

/Torsten

onclez...@gmail.com

unread,
Jan 29, 2015, 1:25:58 PM1/29/15
to sculptor...@googlegroups.com
Hi,

I have the same problem and the project.nature=presentation-tier in the src/main/resources/generator/sculptor-generator.properties of the web:
/helloworld/src/main/resources/generator/sculptor-generator.properties :
project.nature=business-tier
cartridges=builder
generate.modeldoc=false
generate.umlgraph=false


/helloworld/src/main/resources/model.btdesign :
import "classpath:/model-person.btdesign"
Application Universe {
    basePackage=org.helloworld
}

/helloworld/src/main/resources/model-person.btdesign
ApplicationPart Planet {
 
    Module planet {

        Service PlanetService {
            findById => PlanetRepository.findById;
            findAll => PlanetRepository.findAll;
            save => PlanetRepository.save;
            delete => PlanetRepository.delete;
        }
       
        Entity Planet {
            scaffold
            String name
            int diameter
            int population
            Repository PlanetRepository {
                findById;
                save;
                delete;
                findAll;
            }
        }
    }
}

/helloworld-web/src/main/resources/generator/sculptor-generator.properties
project.nature=presentation-tier
generate.module.planet=false
generate.resource=true
generate.restWeb=true
generate.modeldoc=false
generate.umlgraph=false


/helloworld-web/src/main/resources/model.btdesign
import "classpath:/model-person.btdesign"

Application Universe {
    basePackage=org.helloworld
   
    Module planetweb {
        Resource FrontResource {
            String front return="redirect:/rest/planet";
        }
       
        Resource PlanetResource {
            String createForm;
            create => PlanetService.save;
            show => PlanetService.findById;
            showAll => PlanetService.findAll;
            delete => PlanetService.delete;
        }
    }
}

When i launch mvn jetty:run
java.lang.IllegalStateException: Conflicting persistence unit definitions for name 'UniverseEntityManagerFactory': file:/D:/mna/java/mvnrepos/org/helloworld/helloworld/1.0-SNAPSHOT/helloworld-1.0-SNAPSHOT.jar, file:/D:/mna/java/workspace-mda/ArchetypeTutorial/helloworld-web/target/classes
I have 2 pesistence.xml generated
  • /helloworld/src/generated/resources/META-INF/persistence.xml
  • /helloworld-web/src/generated/resources/META-INF/persistence.xml
They are exactly the same !
Any ideas ?

Regards

Torsten Juergeleit

unread,
Feb 1, 2015, 1:30:06 PM2/1/15
to sculptor...@googlegroups.com
You're right, defining "project.nature=presentation-tier" in the web project is not sufficient yet to get rid of all persistence-related artefacts (persistence*.xml, datasource, DbUnit test data, ...). This has to be taken care of in the generators PropertiesBase. initDerivedDefaultsForNonBusinessTier() yet.

Meanwhile you have to add "jpa.provider=none" to the web projects "sculptor-generator.properties" as a workaround.

/Torsten

onclez...@gmail.com

unread,
Feb 1, 2015, 3:38:55 PM2/1/15
to sculptor...@googlegroups.com
Hi,
Great ! The persistence.xml is now not generated ! But... Here the generated show method in PlanetResourceBase

    @RequestMapping(value = "/planet/{id}", method = RequestMethod.GET)
    public String show(@PathVariable("id") String id, ModelMap modelMap) throws PlanetNotFoundException {
        PlanetDTO result = planetService.findById(serviceContext(), id);
        modelMap.addAttribute("result", result);
        return "planet/show";
    }

The id parameter is a String and not a Long !!
I set 'id.type=Long' in the web sculptor-generator.properties but no change...

Furthermore, here the updateForm declaration
public abstract String updateForm(String id, ModelMap modelMap) throws Exception;

But i think it's the same problem.

An idea ?



Le vendredi 4 juillet 2014 09:05:54 UTC+2, Holger Berndt a écrit :

onclez...@gmail.com

unread,
Feb 1, 2015, 3:44:18 PM2/1/15
to sculptor...@googlegroups.com
But it's work with 'javaType.IDTYPE=Long'

Thanks !!!


Le vendredi 4 juillet 2014 09:05:54 UTC+2, Holger Berndt a écrit :

Torsten Juergeleit

unread,
Feb 1, 2015, 4:22:57 PM2/1/15
to sculptor...@googlegroups.com
Great, you find the right solution. The reason for the ID type is set to String is "jpa.provider=none" (see PropertiesBase.initDerivedDefaultsWithoutPersistence()).

This difference in ID type between both projects is due to the fact that your domain objects (here Planet) are generated with "project.nature=business-tier" (which uses the default "jpa.provider=hibernate" and "javaType.IDTYPE=Long").

So to omit only the generation of "persistence*.xml" (while keeping the correct ID type) you can use "generate.jpa.annotation=false" instead of "jpa.provider=none".

/Torsten
Reply all
Reply to author
Forward
0 new messages