As activeandroid library suggests, when declaring a model class object to use annotation unique and index annotation parameters for unique constraint and indexing for a column respectively here,
/**activeandroid imports**/
import com.activeandroid.annotation.Column;
import com.activeandroid.Model;
....
#Table(name="Product")
public class Product extends Model{
...
/**issue: index is not a valid parameter for Column annotation**/
#Column(name = "Category", index = true)
public String category;
...
}
I tried to implement this but the annotation parameters index or unique are not available in the library.
I am using version 3.0 jar
Tried version3.1 beta also,same issue there.
While 3.1 is the latest jar available, am I missing something? Please suggest a solution to create indexes when using activeandroid library.
Thanks
Check if you are extending the Model in your Category Class
public class Category extends Model {}
if no, please post the entire Class and Error log.
Related
I just upgraded my project to spring5 which is causing the below error for the code which was working fine with earlier spring version.
The problem is JPA should map aNumber to ANumber but its not doing so its taking ANumber as ANumber rather than aNumber which is causing this issue.
I see one thread for spring team but cannot see the resolution here: https://github.com/spring-projects/spring-data-jpa/issues/1247
I tried to search everywhere but didn't find anything useful.
Domain Class:
#Data
#Entity
public class Statistics {
#Id
private Long id;
private String aNumber;
private Integer dispositionCode;
#CreatedDate
private OffsetDateTime created;
}
the method in Repository interface:
Optional<Statistics> findFirstByIdAndANumberAndDispositionCodeInOrderByCreatedDesc(Long id, String aNumber, Integer... dispositionCode);
Note: i know id can return unique result just to make exact example I made that change.
I was facing this problem after the JPA version upgrade which state that all the names were correct and mapped perfectly.
The solution I found was defining the native query within the #Query annotation of the spring data JPA because the problem was occurring when JPA was trying to create the JPA Named Query.
#Query(nativeQuery = true, value = "Your Query here")
Optional<Statistics> findFirstByIdAndANumberAndDispositionCodeInOrderByCreatedDesc(Long id, String aNumber, Integer... dispositionCode);
This might not be the best solution but in my case I was not supposed to change the version as it was coming from the parent POM and this was the easiest solution which I could do.
I have a class that looks like this
#Data
#NodeEntity
public class StoryCharacter {
#Index(unique = true)
private String agnosticId;
private String name;
#Relationship(type = "FAMILIAR_WITH")
private Set<StoryCharacter> acquaintances;
}
I needed a custom ID that is not related to the default long id. So I introduced a field and set it as index.
But how to find the object by that id?
I wanted to do it like this
session.openSession().load(StoryCharacter.class, "custom_id")
but it fails with error that it must be Long. I assume that maybe I need to use Filter object for search by that id. Or is there another way?
If you want to use a custom id the field has to be annotated with #Id instead of #Index(unique=true). In cases you do not want to set the id manually, there is an option to provide a id generation strategy (more details in the documentation.
You are seeing this error because Neo4j-OGM cannot determine what type your id field has and falls back to the standard Long. If you define your id as mentioned above, the load will work.
Given an #Entity declared with the following fields:
#Id
private String idgeo;
private String isoCtryCd;
private String randomField;
with the default spring configuration I get resource paths ending with .../{idgeo}.
Is there an option in the spring configuration to use other (unique) fields as the resource path ending? In my example it'd be .../{isoCtryCd}
Thank you!
Actually this feature will be introduced in Spring Data Rest 2.5. Currently there is a 2.5.0.M1 milestone release containing this feature.
This part of the documentation shows how to use a different entity attribute for item resource uris.
http://docs.spring.io/spring-data/rest/docs/2.5.0.M1/reference/html/#_customizing_item_resource_uris
I'm currently working on a project that involves the use of Hibernate Search. Currently the project uses pure SQL for its searches and we would like to use a text search instead (Needing to know and correctly spell the first word can get annoying).
The schema is that a product can have multiple versions and the current version contains the name of the product.
Public Class Product extends ProgEntity
{
private List<ProductVersion> versions = new ArrayList<ProductVersion>();
...
}
Public Class ProductVersion extends ProgEntity
{
String productName;
...
}
I need to be able to search for a product based on its name. I was able to index the ProductVersions by productName with little issue however indexing Product is proving to be more of an issue.
After some research this is what I have however when I update the product to the DB no index is created.
#Entity
#Indexed
Public Class Product extends ProgEntity
{
#IndexedEmbedded
private List<ProductVersion> versions = new ArrayList<ProductVersion>();
...
}
#Entity
#Embeddable
Public Class ProductVersion extends ProgEntity
{
#Field
String productName;
...
}
The DocumentID is part of ProgEntity. I need to be sure that if I update Product or Product Version that it will be indexed properly which does not seem to be happening now.
Any suggestions on what I am doing incorrectly?
You don't have a relationship (eg many-to-one, many-to-one) between Product and ProductVersion mapped in the code you posted. This relationship must be bi-directional. Annotate the Product's collection field with #IndexedEmbedded, and the inverse field on the ProductVersion side with #ContainedIn, and you should be all set.
Using #Entity and #Embeddable on ProductVersion seems wrong. There are also some JPA annotations missing. Is the version collection mapped as #ManyToOne or #ElementCollection.
Have you checked your hibernate configuration and log files? Which directory provider are you using?
I want to try to make unit test with DBUnit but I have a problem with my dataset.
Here is my persistence object:
#Entity
#Table(name = "personnes")
public class Personne implements Serializable {
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private Integer pk;
#Column
private String name;
}
And my dataset:
<?xml version='1.0' encoding='UTF-8'?>
<dataset>
<personnes name="toto" pk="1" />
</dataset>
My problem is with the name column, I get this error:
org.dbunit.dataset.NoSuchColumnException: personnes.NAME - (Non-uppercase input column: name) in ColumnNameToIndexes cache map. Note that the map's column names are NOT case sensitive.
I don't understand why dbunit search a column "NAME" whereas my column is "name".
Thanks for your help.
I've been fighting this for a while, and keep coming back to this issue, which doesn't seem to have a solution yet.
In Unitils 3.4.1, they added a new property, org.dbunit.database.IMetadataHandler.implClassName
In my unitils.properties file, I added the following line
org.dbunit.database.IMetadataHandler.implClassName=org.dbunit.ext.mysql.MySqlMetadataHandler
Yes, I know, according to Unitils' website, there is no version 3.4.1, but you can get the latest version via Maven.
link to issue report
Since you don't specify the column name in the mapping, I guess the underlying ORM framework generates the column name "NAME" for it.
To resolve this error/warning, you could add the column name to the mapping
#Column( name = "name")
resulting in a lower-case column name or use upper-case notation in your dataset
<personnes NAME="toto" pk="1" />
leaving the upper-case column name.
You need to set the following to true
DatabaseConfig.FEATURE_CASE_SENSITIVE_TABLE_NAMES
within your DatabaseConfig object.
See org.dbunit.dataset.NoSuchTableException: Did not find table 'xxx' in schema 'null'
Try to set datatype factory for your databases.
All available factories can be found on this link. http://dbunit.sourceforge.net/apidocs/org/dbunit/dataset/datatype/IDataTypeFactory.html
Choose factory which belongs to your database.
Implement method setUpDatabaseConfig in your test class and set factory.
protected void setUpDatabaseConfig(DatabaseConfig config) {
config.setProperty( DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new OracleDataTypeFactory() );
}