NHibernate : Store VARBINARY to MAX - sql-server-2008

I am using following mapping to store a Serializable object to SQL Server 2008:
<class name="EMSApplication.Data.Domain.Configuration, EMSApplication.Data" table="ems_Configurations" proxy="EMSApplication.Data.Domain.IConfiguration, EMSApplication.Data" lazy="true">
<id name="Id" type="System.Int32">
<column name="Id" not-null="true"/>
<generator class="native"/>
</id>
<property name="Settings" type="Serializable">
<column name="Settings" not-null="true"/>
</property>
</class>
It is generating a varbinary(8000) for column type of the database. How can I make it to use varbinary(max)?
If I use:
<property name="Settings" type="Serializable" length="2147483647">
<column name="Settings" not-null="true"/>
</property>
It is also truncated to 8000. I am using NHibernate3.2(not fluent).

According to the nHibernate documentation, "length" is not an attribute/property of <property> but instead should be used in <column>.
This section shows that "length" is not a part of <property> :
http://nhibernate.info/doc/nh/en/index.html#mapping-declaration-property
This section shows that "length" is a part of <column> :
http://nhibernate.info/doc/nh/en/index.html#toolsetguide-s1-2
That last section (20.1 and the Table 20.1 Summary) shows that "sql-type" is also part of <column> so try one of these variations:
<property name="Settings" type="Serializable">
<column name="Settings" not-null="true" length="2147483647"/>
</property>
or
<property name="Settings" type="Serializable">
<column name="Settings" not-null="true" sql-type="varbinary(max)"/>
</property>
Edit:
This question seems to be a duplicate of:
How do I get fluent nhibernate to create a varbinary(max) field in sql server
but that information is almost 3 years old and the newer version of nHibernate might have corrected for this (I have no way to test this).
The following page appears to also be the same issue and is much more recent:
Binary Blob truncated to 8000 bytes - SQL Server 2008 / varbinary(max)

Related

Apache Ignite use table names instead of cachename in a query

i have an application made in java that queries a schema many times (about 1000) for each request made by the user.
This was initially designed in this way many years ago and currently the code refactor would be too risky for the complexity of the methods.
Anyway, in order to leverage the DB effort i thought to introduce an Ignite layer to cache the biggest part of the data queried that is basically static, so i would expect that many of those queries will be faster and not on the DB anymore.
I've configured ignite properly on the server to cache the tables I need, and everything's fine until I tried to query on DBEaver or Squirrel and i discovered that the name of the tables to query on the Ignite DB is what in the ignite configuration is called property name=cacheName".
I don't want to put the hands on the code to change the queries one by one, so i would assume there's a way to keep the queries as the same as those are on the Oracle DB.
Example
In oracle DB i have
<Schema_Name>.<Table_Name>
and my queries in the code are something like
"select * from <Table_Name> where x"
In Ignite schema instead i have
cacheName.<Table_Name>
so in order to query this my query should be transformed in something like
"select * from cacheName.<Table_Name> where x"
Seems like in Ignite the cacheName is considered as a Schema, the problem is that each single table has different schema in this way. Should I consider to refactor all the queries or is there a way to mantain the same query format?
my configuration is something like this
Taken from one table configuration
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="name" value="<TableName>Cache"/>
<property name="cacheMode" value="PARTITIONED"/>
<property name="atomicityMode" value="ATOMIC"/>
<property name="cacheStoreFactory">
<bean class="org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStoreFactory">
<property name="dataSourceBean" value="dsOracle"/>
<property name="dialect">
<bean class="org.apache.ignite.cache.store.jdbc.dialect.OracleDialect">
</bean>
</property>
<property name="types">
<list>
<bean class="org.apache.ignite.cache.store.jdbc.JdbcType">
<property name="cacheName" value="<TableName>Cache"/>
<property name="keyType" value="package.obfuscated.key"/>
<property name="valueType" value="package.obfuscated.type"/>
<property name="databaseSchema" value="<DBSchemaName>"/>
<property name="databaseTable" value="<TableName>"/>
<property name="keyFields">
<list>
<bean class="org.apache.ignite.cache.store.jdbc.JdbcTypeField">
.
.
.
[list of table fields]
.
.
Thanks a lot
In your cache definition, you can set the SQL Schema:
var cacheConfiguration = new CacheConfiguration<PersonKey,Person>()
.setName("PERSON_CACHE")
.setSqlSchema("MY_SCHEMA")
.setCacheMode(CacheMode.PARTITIONED)
.setIndexedTypes(PersonKey.class, Person.class);
var cache = ignite.<PersonKey,Person>getOrCreateCache(cacheConfiguration);
This creates a table that's visible in SQL as MY_SCHEMA.Person.

How to set column default value to today's date in SQL using XML

I want to add a column to one of my SQL schema's tables.
I have tried the following:
<property name="now" value="now()" dbms="mysql"/>
<changeSet author="Trey Collier" id="SCHEJ-376">
<addColumn tableName="schedule">
<column name="dateLastPublished" type="DATETIME" defaultValueDate="${now}">
<constraints nullable="false" />
</column>
</addColumn>
</changeSet>
However, this inserts the date in the format YYYY-MM-DD hh:mmm:ss, but I only want the YYYY-MM-DD part of it. How can I change my current XML code to make this happen? Thanks
You should change defaultValueDate="${now}" with defaultValueDate="(DATE(CURRENT_TIMESTAMP))" and type="DATETIME" with type="DATE"

How to manually increment UNIX_TIMESTAMP() when insert a new row with liquibase?

I have a cart table with a cart_number column which I would like to be the current time in milliseconds.
I've created a database change log file and everything works fine but the problem is that the span of time between 2 inserts is too short to get a "unique" cart_number. Here is the liquibase insert:
<property name="now" value="UNIX_TIMESTAMP()" dbms="mysql"/>
<changeSet id="2" author="Me">
<insert tableName="cart">
<column name="user_id" value="1"/>
<column name="cart_number" valueDate="${now}"/>
</insert>
<insert tableName="cart">
<column name="user_id" value="2"/>
<column name="cart_number" valueDate="${now}"/>
</insert>
</changeSet>
And I know this isn't a solution, but I've tried to write something like ${now+1} but it didn't worked. Any help would be appreciated. Thank you in advance.

Can Spring Batch use MySQL for its internal BATCH_ tables?

I have been using Oracle for this without any trouble but I then had to switch it all over to use MySQL and am seeing this error during initialization:
org.springframework.dao.DataAccessResourceFailureException: Could not obtain sequence value; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown table 'BATCH_JOB_SEQ' in field list
The tables are present so its something else going wrong here. After debugging I captured the actual sql it was trying to perform to get the sequence:
select BATCH_JOB_SEQ.nextval from dual;
Which is obviously an Oracle statement!
My config states this to setup the connection:
<bean id="springDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://10.252.205.5:3306/MASKNG" />
<property name="username" value="MASKNG" />
<property name="password" value="maskng" />
</bean>
Any help appreciated...
jobRepositoryFactoryBean.setDatabaseType(“mysql”)
Seems like there is no BATCH_JOB_SEQ created here in MySQL.
You need to create the sequence for that. Refer How do I create a sequence in MySQL? for creating sequence.

EF 4.1 is trying to insert values in identity column despite StoreGeneratedPattern being set to Identity in SSDL

I have a table called ScanMasters in SQL Server 2008 which has a column called PresentationAuditId as the primary key. This column is also a foreign key. The table also has an identity column called ScanPartId. I am using Entity Framework 4.1 to generate POCOs based on my database. The EF SSDL represents the entity in this manner:
<EntityType Name="ScanMasters">
<Key>
<PropertyRef Name="PresentationAuditId" />
</Key>
<Property Name="ScanPartId" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
<Property Name="RackNum" Type="int" />
<Property Name="LoadDatetime" Type="datetime" />
<Property Name="PresentationAuditId" Type="bigint" Nullable="false" />
<Property Name="Item" Type="varchar" MaxLength="31" />
</EntityType>
When I add new data for this entity and do SaveChanges(), I am getting the following error:
Cannot insert explicit value for identity column in table 'ScanMasters' when IDENTITY_INSERT is set to OFF.
Can we have a non-primary key column as an identity column in EF 4.1? How can I go about this?