Hi Marianne,
OK, have a theory for you and something to try.
What I can see is that the definition of the table regulation_dependency is
incorrect:
10:53:34,420 [Schema main DEBUG] CREATE TABLE
regulation_dependency
(
regulationid LONG VARBINARY NOT NULL,
dependentregulationid LONG VARBINARY NOT NULL,
idx INTEGER NOT NULL,
CONSTRAINT regulation_dependency_pk PRIMARY KEY (idx)
) ENGINE=INNODB
... those LONG VARBINARY columns are basically BLOBs, which is incorrect;
I'd imagine they ought to be a simple integer or long. It's because of
that issue that we later see the error:
10:53:34,531 [Schema main DEBUG] ALTER TABLE
regulation_dependency ADD CONSTRAINT regulation_dependency_fk1 FOREIGN KEY
(regulationid) REFERENCES regulation (id)
10:53:34,534 [Datastore main ERROR] An exception was
thrown while adding/validating class(es) : BLOB/TEXT column 'regulationid'
used in key specification without a key length
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: BLOB/TEXT column
'regulationid' used in key specification without a key length
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
DataNucleus is trying to set up a FK from the regulation_dependency table
back to its parent, but that's not allowed for BLOBs.
The regulation_dependency table is arising from this code in that class:
@javax.jdo.annotations.Persistent(table="regulation_dependency")
@javax.jdo.annotations.Join(column="regulationId")
@javax.jdo.annotations.Element(column="dependentRegulationId")
private SortedSet<Regulation> dependentRegulations = new
TreeSet<Regulation>();
public SortedSet<Regulation> getDependentRegulations() { ... }
public void setDependentRegulations(final SortedSet<Regulation>
dependentRegulations) { ... }
which looks ok to me.
My strong suspicion is that Regulation isn't being correctly enhanced. In
that case DN will try to treat it like a value, not an entity;in other
words it'll try to serialize it as a byte[] using Java's serialization
mechanisms. This is probably why we are seeing the regulation_dependency
table defined incorrectly.
~~~
You also posted a separate message (which Martin replied to) regarding DN
enhancement error; so if you follow Martin's advice on that, hopefully this
issue will clear up too.
Another thing you could do is to run the app from the mvn command line (eg
mvn clean install followed by mvn -P self-host antrun:run) and see if it
runs ok. If so, then we know the issue is within your IDE.
HTH
Dan
On 20 April 2015 at 10:10, Marianne Hagaseth <
[email protected]> wrote:
> Hi!
> The code at the end of this mail creates the following tables (for mysql),
> and the following error:
>
> 10:53:34,420 [Schema main DEBUG] Check of existence
> of regulation_dependency returned no table
> 10:53:34,420 [Schema main DEBUG] Creating table
> regulation_dependency
> 10:53:34,420 [Schema main DEBUG] CREATE TABLE
> regulation_dependency
> (
> regulationid LONG VARBINARY NOT NULL,
> dependentregulationid LONG VARBINARY NOT NULL,
> idx INTEGER NOT NULL,
> CONSTRAINT regulation_dependency_pk PRIMARY KEY (idx)
> ) ENGINE=INNODB
> 10:53:34,453 [Schema main DEBUG] Execution Time = 33
> ms
> 10:53:34,457 [Schema main DEBUG] Creating candidate
> key "Regulation_description_must_be_unique" in catalog "" schema ""
> 10:53:34,457 [Schema main DEBUG] ALTER TABLE
> regulation ADD CONSTRAINT regulation_description_must_be_unique UNIQUE
> (ownedby,regulationtitle)
> 10:53:34,510 [Schema main DEBUG] Execution Time = 53
> ms
> 10:53:34,520 [Schema main DEBUG] Creating index
> "regulation_dependency_n49" in catalog "" schema ""
> 10:53:34,520 [Schema main DEBUG] CREATE INDEX
> regulation_dependency_n49 ON regulation_dependency (regulationid)
> 10:53:34,525 [Schema main DEBUG] Creating index
> "regulation_dependency_n50" in catalog "" schema ""
> 10:53:34,525 [Schema main DEBUG] CREATE INDEX
> regulation_dependency_n50 ON regulation_dependency (dependentregulationid)
> 10:53:34,529 [Schema main DEBUG] Creating foreign
> key constraint : "regulation_dependency_fk2" in catalog "" schema ""
> 10:53:34,529 [Schema main DEBUG] ALTER TABLE
> regulation_dependency ADD CONSTRAINT regulation_dependency_fk2 FOREIGN KEY
> (dependentregulationid) REFERENCES regulation (id)
> 10:53:34,531 [Schema main DEBUG] Creating foreign
> key constraint : "regulation_dependency_fk1" in catalog "" schema ""
> 10:53:34,531 [Schema main DEBUG] ALTER TABLE
> regulation_dependency ADD CONSTRAINT regulation_dependency_fk1 FOREIGN KEY
> (regulationid) REFERENCES regulation (id)
> 10:53:34,534 [Datastore main ERROR] An exception was
> thrown while adding/validating class(es) : BLOB/TEXT column 'regulationid'
> used in key specification without a key length
> com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: BLOB/TEXT
> column 'regulationid' used in key specification without a key length
> at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
> Method)
>
>
> code:
>
>
> //region > Dependent Regulations (property), add (action), remove
> (action)
> // overrides the natural ordering
> public static class RegulationsComparator implements
> Comparator<Regulation> {
> @Override
> public int compare(Regulation p, Regulation q) {
> Ordering<Regulation> byRegulationTitle = new
> Ordering<Regulation>() {
> public int compare(final Regulation p, final Regulation q)
> {
> return
> Ordering.natural().nullsFirst().compare(p.getRegulationTitle(),
> q.getRegulationTitle());
> }
> };
> return byRegulationTitle
> .compound(Ordering.<Regulation>natural())
> .compare(p, q);
> }
> }
>
> @javax.jdo.annotations.Persistent(table="regulation_dependency")
> @javax.jdo.annotations.Join(column="regulationId")
> @javax.jdo.annotations.Element(column="dependentRegulationId")
> private SortedSet<Regulation> dependentRegulations = new
> TreeSet<Regulation>();
> @MemberOrder(name="Regulation", sequence = "98")
>
> //@CollectionInteraction
> //@Collection(domainEvent=Regulation.Dependencies.class)
>
> @CollectionLayout(sortedBy=RegulationsComparator.class,render=RenderType.EAGERLY)
> public SortedSet<Regulation> getDependentRegulations() {
> return dependentRegulations;
> }
> public void setDependentRegulations(final SortedSet<Regulation>
> dependentRegulations) {
> this.dependentRegulations = dependentRegulations;
> }
> public void addToDependentRegulations(final Regulation regulation) {
> getDependentRegulations().add(regulation);
> }
> public void removeFromDependentRegulations(final Regulation
> regulation) {
> getDependentRegulations().remove(regulation);
> }
>
> // This is the add-Button!!!
> @MemberOrder(name="Dependent Regulations", sequence = "10")
> public Regulation add(final @ParameterLayout(typicalLength=20)
> Regulation regulation) {
> // By wrapping the call, Isis will detect that the collection is
> modified
> // and it will automatically send CollectionInteractionEvents to
> the Event Bus.
> // ToDoItemSubscriptions is a demo subscriber to this event
>
> wrapperFactory.wrapSkipRules(this).addToDependentRegulations(regulation);
> return this;
> }
>
> public List<Regulation> autoComplete0Add(final @MinLength(2) String
> search) {
> final List<Regulation> list = regulations.autoComplete(search);
> list.removeAll(getDependentRegulations());
> list.remove(this);
> return list;
> }
>
> public String disableAdd(final Regulation regulation) {
> if(isFinalized()) {
> return "Cannot add dependencies for items that are Finalized";
> }
> return null;
> }
> // validate the provided argument prior to invoking action
> public String validateAdd(final Regulation regulation) {
> if(getDependentRegulations().contains(regulation)) {
> return "Already a dependency";
> }
> if(regulation == this) {
> return "Can't set up a dependency to self";
> }
> return null;
> }
>
> // This is the Remove-Button!!
> @MemberOrder(name="Dependent Regulations", sequence = "20")
> public Regulation remove(final @ParameterLayout(typicalLength=20)
> Regulation regulation) {
> // By wrapping the call, Isis will detect that the collection is
> modified
> // and it will automatically send a CollectionInteractionEvent to
> the Event Bus.
> // ToDoItemSubscriptions is a demo subscriber to this event
>
> wrapperFactory.wrapSkipRules(this).removeFromDependentRegulations(regulation);
> return this;
> }
> // disable action dependent on state of object
> public String disableRemove(final Regulation regulation) {
> if(isFinalized()) {
> return "Cannot remove dependencies for items that are
> Finalized";
> }
> return getDependentRegulations().isEmpty()? "No dependencies to
> remove": null;
> }
> // validate the provided argument prior to invoking action
> public String validateRemove(final Regulation regulation) {
> if(!getDependentRegulations().contains(regulation)) {
> return "Not a dependency";
> }
> return null;
> }
> // provide a drop-down
> public Collection<Regulation> choices0Remove() {
> return getDependentRegulations();
> }
> //endregion Dependent Regulations
>
>
> So the question is how I can set the type of the keys so that they are
> accepted?
>
> Best,
> Marianne.
>