How to make a class persistent capable - java

I am trying to create a class whose code snippet is as follows:
import java.io.Serializable;
import java.util.Date;
import com.objy.db.app.ooObj;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
#PersistenceCapable
public class Student extends ooObj implements Serializable {
...
}
Now, the program is not even getting compiled, as it says t cannot recognize ooObj class, and without this, the logger returns the following:
org.datanucleus.exceptions.ClassNotPersistableException: The class "project2.Student" is not persistable. This means that it either hasnt been enhanced, or that the enhanced version of the file is not in the CLASSPATH (or is hidden by an unenhanced version), or the Meta-Data/annotations for the class are not found.]]
Could someone please suggest how to either make the class persistent capable or some maven dependency to use ooObj.

Do a Google search for "com.objy.db.app.ooObj" and try to find the missing dependency yourself!
I guess you need to download Objectivity/DB for Java: http://support.objectivity.com/downloads

Related

Maven can't find class even though package is included

I have the following code:
package osu.cs362.URLValidator;
import static org.junit.Assert.*;
import org.junit.Test;
import java.util.*;
import static org.mockito.Mockito.*;
public class DomainValidatorTest {
RegexValidator rev = mock(RegexValidator.class);
}
This includes the package osu.cs362.URLValidator which contains RegexValidator.
However, when running mvn test I get:
cannot find symbol class RegexValidator
Why can't it find this class? Is this a pom.xml issue?
It is not a Maven problem.
If the RegexValidator class had the declaration like that :
package osu.cs362.URLValidator;
public class RegexValidator {
...
}
you would have not the problem. So I suppose it is not the case.
Besides, filesytem folders are not Java packages.
For example, nobody prevents you from declaring your class in the folder :
osu/cs362 of your classpath folder and declaring the package of the class like that: fictive.folder.
The class will compile.
It is the case for DomainValidatorTest. The package is not symmetric with the folder layout but the class is found by the compiler and it doesn't cause a compilation error.
But of course, it is a bad practice and it is misleading. That's why packages should always be symmetric to the folders layout.
You shoud move your DomainValidatorTest.java to directory:
src/test/java/osu/cs362/URLValidator
Directory structure should be the same as java package.

Where am I going wrong in trying to import a class?

Here's the code for the source file:
package moa4;
public class Book {
....
}
And for the destination file:
import moa4.Book;
public class Library {
...
}
The source and the destination are both saved in the same directory with the address:
C:\Users\\java\M\moa4
I'm getting the following error: package moa4 does not exist
You asked Library to import a package moa4.Book but you defined no such package. Instead, you defined a type Book inside package moa4, and that is not consistent with your import directive.
You could either import the package, or make that an import static of the class, but since Book and Library are both in the same package you don't need the import directive at all.
As mentioned, C:/Users/java/M needs to be in your classpath ("-cp" option).

eclipse: import (classname) cannot be resolved

I am new in using eclipse java using multiple .java files. My eclipse java project consist of one project file two package files, each with one .java class
My 2nd java class import the 1st java class/package, like so
VerifyLogin.java
package VerifyLogin;
import ArgumentCountException;
ArgumentCountException.java
// ...
The problem is VerifyLogin.java is getting an error
Import ArgumentCountException cannot be resolved
Or any reference I have to ArgumentCountException cannot be resolved to a type.
In java if you need to import a class then you need to use the full qualified name for that class, as the following:
import packageName.YourClass;
For Example, if your need to use Scanner class, then you need to import it as:
import java.util.Scanner;
But if the class was withing the same package, you don't need to import it.
When importing your class, it should be done as below:
//Current package name for the VerifyLogin Class (All package names should be lowercase by convention)
package packageforcurrentclass;
//Import statements: import thedependencyclasspackage.thedependencyclassname
import exceptionpackage.ArgumentCountException;
public class VerifyLogin
{
...
}

Getting Error for package name in netbeans

I am using one .java file and i have given a package name as com.onlinmebank but netbeans displaying error at this package declaration line as Incorrect Package.
Following is the package declaration code.
package com.onlinebank;
import java.sql.*;
import java.util.*;
public class BankCommons{
//All Code Here
}
Can Anybody tell me why i am getting this error
All Java keywords are lower-case!
So, this should work:
package com.onlinebank;
import java.sql.*;
import java.util.*;
public class BankCommons {
//All Code Here
}
And keep in mind, that the file BankCommons.java must be placed in the directory com/onlinebank.
In package, p should be small not Package(no captial P).
Also in public class p should be small. Similarily for Import also.
Important note all java keywords are in lower cases

Permanently hidden warning from Scalac parsing Java code - compiler bug?

The scalac Java parser is taking objection to my Java code
imported `Entity' is permanently hidden by definition of object Entity in package domain Asset.java
This seems to be a collision between an import and a class with the same name in the package being compiled.
In my package I have a class
package iMP2020.domain;
public interface Entity {
public Serializable getId();
}
with the same name as an imported class from a different package
package iMP2020.domain;
import javax.persistence.Entity; // compiler warning
#Entity
public class Asset {
where it is complaining about the import. Javac is quite happy. Note that I don't have to reference my version of the class- just its existence is enough to trigger the warning on the import.
I can fix this by removing the import and explicitly referencing #Entity, but is it a bug in the compiler?
I don't seem to be able to reproduce this except with the Scala Eclipse plugin, so I'm going to wait for that to stabilise before coming to a conclusion.
You have two Entity references, one for your interface, and another one for javax.persistence.Entity.
Try to replace the second one with the full qualified name, removing the import:
package iMP2020.domain;
public interface Entity {
public Serializable getId();
}
and
package iMP2020.domain;
#javax.persistence.Entity
public class Asset {
I don't think it is a bug.
It doesn't make sense for an import to have the same name as a package member.

Categories