I'm using JPA with a postgresql database and also using Hibernates hbm2ddl to generate the initial DB schema.
I have a Java String field in my entity object that will need to be large. When I annotate it with #Lob hbm2ddl generates an oid db column, however I can also use #Column(columnDefinition = "TEXT") to get a TEXT db column.
I've tried searching the internet but I can't find any comparison between the performance or other benefits of oid's vs TEXT columns. Is there any reason to prefer one over the other?
Related
I have an Oracle database that is currently being migrated to an AWS Aurora Postgres database. As part of this I have had to update some of the datatypes in our sql files for creating tables e.g. changing NUMBER to NUMERIC etc. It has been going well but I am now coming across the following error when trying to insert some data into a table using spring data/JPA
ERROR: column "some_table_column" is of type numeric but expression is of type boolean
I can identify the issue is probably that the java class defines this column like
#Column(name = "SOME_TABLE_COLUMN", nullable = false)
private boolean someTableColumn;
while the sql file defines it like
CREATE TABLE MY_TABLE
(
SOME_TABLE_COLUMN NUMERIC(1) DEFAULT 0 NOT NULL,
etc..
Don't ask why it has been defined like this, I didn't write this code, I've just inherited it. But this has not been an issue ever with the Oracle database, and I'm only seeing the error now when running against Postgres. Does Oracle do some sort of implict conversion behind the scene that Postgres doesn't do? Is there a way I can resolve this without having to migrate the column to a boolean datatype?
I'm using JPA 2.1 eclipselink to call Stored Procedures from the database and i don't want to hardcoded the schema name. Is there a way to switch between schemas dynamically?
I'm using JPA 2.1, EclispseLink 2.5.2, weblogic 12.1.3
EDITED: Schema name is unknown, so i cannot create mapping file for each schema. Plus I might have 5-10 schemas in the database. What I want is a way to go to the database, select a schema name and switch them at runtime
I need to add a nullable column to a database without breaking other EF users of the database. Will I break them?
I have tested this with Code First. If you add a Nullable column to the database, EF Code First consumers will not have an issue working with the table.
I store data in table named by month,such as data201201,data201202 and so on,table is created in the first day of month,all tables have same struct.I design this because each month ten million rows increase and I have only sqlserver standard version so Partition table can not be used.
Before use entity framework,i used sql string to query data,so I can change tablename in sql string by query condition.
Is these any way that I can query related table in Entity Framework?
I have two idea:
1.another table design that can support such big data and minor cost?
2.Intercept ef's query and change table name by query condition,and continue this query,but how and where i can do so?
I am working with DB2 Universal database having lots of tables with columns of datatype CHARACTER. Length of these columns is variable (greater than 1 e.g. 18). As i execute a Native query using JPA it selects only first character of the column. Seems CHARACTER datatype is mapped to Java Character.
How can i get full contents in DB column. I can not change the database bening on Vendor side. Please note i need to do it both ways, i.e. :
Using JPQL ( is attribute columnDefinition can work in this case)
Using native DB query (no pojo is used in this case and i have no control over datatypes)
i am using Hibernate implementation of JPA provided by spring.
If these columns are actually common in your database, you can customize a dialect used by Hibernate. See comments to HHH-2304.
I was able to cast the column to VARCHAR to produce padded String results from createNativeQuery:
select VARCHAR(char_col) from schema.tablename where id=:id