Why eclipselink convert BIGINT to string type? - jpa

I am using EclipseLink 2.6 and MySQL 5.
In the database, I design a table named User which has a id column as BIGINT datatype.
Then I use Eclipse to generate entity class from the table.
After generating, the entity class User has the id field as String, which I would have expected as long type.
I tried to perform CRUD operations and all worked just fine.
Why a String type can be mapped to a BIGINT type.

Related

How to use a custom postgresql type in seaORM?

I have the following table in postgres
create table retailers(id: integer, name: citext);
citext is just case insensitive text in postgres. How do I modify the Entity creation in SeaORM to support that?
When I generate entities in SeaORM in rust, I get the following error:
error: Missing macro attribute, either `string_value` or `num_value` should be specified or specify repr[X] and have a value for every entry
--> src/entity/sea_orm_active_enums.rs:10:5
How do I "register" new types in seaORM in Rust?

How to have constraints in graph database such as orientDB?

I am coming from the RDBMS world. so forgive if I ask a badly phrased question.
I have a situation where I need to ensure unique or partial unique populating data inside cayley
In RDBMS such as postgres, I can build a table like this:
primary autoincrement key called id
foreignkey to person table called person_id
foreignkey to product table called product_id
foreignkey to price table called price_id
boolean field called is_removed
If i want a unique constraint such as the entire table can have a unique index such that product_id and price_id are together as a pair must be unique, I can do that.
if i want a partial unique constraint in postgres where if the is_removed is False, then the person_id, product_id, and price_id are unique.
Then if any of the foreignkeys are null, the constraints are not triggered.
How do I have something this inside a graph database such as orientDB?
My objective is to prevent creating illegal relations in the database
In orientDB you can define a schema for your database.
You have classes instead of tables.
Vertexes and edges are specialized classes.
You can define properties on classes, and define constraints on properties.
As a concrete example, the definition for the a User vertex class :
CREATE CLASS User EXTENDS V;
CREATE PROPERTY User.userId LONG;
CREATE PROPERTY User.description STRING;
CREATE PROPERTY User.screenName STRING;
CREATE PROPERTY User.lang STRING;
CREATE PROPERTY User.location STRING;
CREATE PROPERTY User.fetched BOOLEAN;
CREATE INDEX User.userId ON User(userId) UNIQUE_HASH_INDEX METADATA {ignoreNullValues: true};
CREATE INDEX User.description ON User(description) FULLTEXT ENGINE LUCENE METADATA {ignoreNullValues: true};
These are the links to the official part of the documentation about SQL and schema manipulation:
http://orientdb.com/docs/3.0.x/sql/SQL-Create-Class.html
http://orientdb.com/docs/3.0.x/sql/SQL-Create-Vertex.html
http://orientdb.com/docs/3.0.x/sql/SQL-Create-Edge.html
http://orientdb.com/docs/3.0.x/sql/SQL-Create-Index.html
http://orientdb.com/docs/3.0.x/sql/SQL-Create-Property.html

How to map a column to JSONB instead of JSON, with Doctrine and Postgresql?

In my project I'm using Doctrine doctrine 2.5.4/postgres 9.5. I'm trying to add a jsonb field using YAML:
fields:
obj: json_array
This gets interpreted as a json column type (and not jsonb). The specification notes about picking up json or jsonb:
Chosen if the column definition contains the jsonb option inside the platformOptions attribute array and is set to true.
But platformOptions doesn't seem to work (tried to add it below obj, at the top... with no success). How can I add a jsonb field?
This is supported by doctrine/dbal v2.6+ (it requires PHP 7.1). All you need to do is use json_array and set options={"jsonb"=true} I tested this on doctrine/dbal v2.6.3
This is what it looks like in PHP format:
/**
* #ORM\Column(type="json_array",nullable=true,options={"jsonb"=true})
*/
private $details;
and it creates a query such as (for an existing table):
ALTER TABLE mytable ADD details JSONB NOT NULL;
More details about type mapping can be found at Doctrine mapping matrix.
Use boldtrn/jsonb-bundle, it provides a jsonb doctrine type as well as custom functions to access the special operators provided by the PostgreSQL jsonb data type.

How to handle varchar columns with Entity Framework?

I have a table with a varchar column and I am using Entity Framework to use this column in the WHERE clause.
Entity Framework generates the query with N'' hence the index on the column cannot be used. Is there a way to force Entity Framework to generate varchar query instead of nvarchar one?
It actually depends on how you built your EF model, if you're using its Designer you can specify the required data type for each column (in your case simply set varchar and you're done).
If you're using a code-first approach you have to decorate the property that represents that column with the proper attribute (string objects in .NET are always Unicode so it'll map nvarchar by default), just do this (with data annotations, if you're using StringAttribute then se its IsUnicode property to false):
[Column(TypeName = "varchar")]
public string YourColumnName
{
get;
set;
}
You can use the EntityFunctions.AsNonUnicode(string) method, so then the EF will not pass the string value as nvarchar. I had the same issue with EF 5 and EDMX, where the Oracle database was ignoring a varchar2 column index, and that's worked for me.
var q = (from TableClass t in TableName
where t.varchar2Column == EntityFunctions.AsNonUnicode(someText));
MSDN reference: https://msdn.microsoft.com/pt-br/library/system.data.objects.entityfunctions(v=vs.110).aspx

Oracle database object type import in JPA

Is there a way to import oracle defined object type in JPA. I have a complex object defined in database :
create or replace TYPE "myType"{
someString varchar2(100),
someString2 varchar2(100),
constructor....}
this object type is than used in a database table.
There is no standard support for object-types in JPA.
If you are using EclipseLink, you can use the #Struct annotation to map object-types,
http://www.eclipse.org/eclipselink/documentation/2.5/jpa/extensions/a_struct.htm#CBBDCAHG
If you are mapped a table of the type, and the type has no nested types, then it will just look like a normal relational table, and you can just map in like a normal relational table.