Im trying to resolve an issue where when using NHibernate with a SqlServerCeDriver that uses an image column you receive an error: "Byte array truncation to a length of 8000.". I found the following solution:
http://mgeorge-notes.blogspot.com/2009/05/nhibernate-mapping-from-binary-to.html
And created the following class:
namespace Test
{
public class SqlServerCeDriver_ImageFix : SqlServerCeDriver
{
protected override void InitializeParameter(IDbDataParameter dbParam, string name, SqlType sqlType)
{
base.InitializeParameter(dbParam, name, sqlType);
if (sqlType is BinarySqlType)
{
PropertyInfo dbParamSqlDbTypeProperty = dbParam.GetType().GetProperty("SqlDbType");
dbParamSqlDbTypeProperty.SetValue(dbParam, SqlDbType.Image, null);
}
}
}
}
But when I change the NHibernate mapping from
NHibernate.Driver.SqlServerCeDriver
to
Test.SqlServerCeDriver_ImageFix
I get the error, but I am not sure why.
The inner exception is: "Could not load type Test.SqlServerCeDriver. Possible cause: no assembly name specified."
Anyone have any ideas as to what im doing wrong?
When defining the driver in the config, define it with the AssemblyQualifiedName, i.e.:
Test.SqlServerCeDriver_ImageFix, MyAssemblyThatContainsThisType
Related
When creating a Dataprovider that returns Iterator I have it in my test method, but my intellij-idea marks this return type as invalid and shows the message:
"Data provider must return either Object[][] or Iterator[], or Iterator".
Here is my class/ method:
public class TradeTestDataProvider {
#DataProvider(name = "experimental")
public Iterator<TestCase> createCases() throws IOException {
List<TestCase> test = DataReader.generateCasesFromJson("src/test/resources/json/experimental_test_case");
return test.iterator();
}
}
Please advise, if I am missing something or it is related to TestNG/IDE issue?
Update:
I created a post to discuss this issue with plugin:
topic
When we try to access profile through code we are getting message as below, please advice
The error is:
There was an error in serializing one of the headers in message
EPS_ProfileReadRQRequest: 'Unable to generate a temporary class (result=1).
error CS0030: Cannot convert type 'CRM.ProfileReadRQ.BusinessSystemIdentityInfoSynchronizationCriterionTypeExcludeCombination' to 'CRM.ProfileReadRQ.BusinessSystemIdentityInfoSynchronizationCriterionTypeIncludeCombination'
error CS0029: Cannot implicitly convert type 'CRM.ProfileReadRQ.BusinessSystemIdentityInfoSynchronizationCriterionTypeIncludeCombination' to 'CRM.ProfileReadRQ.BusinessSystemIdentityInfoSynchronizationCriterionTypeExcludeCombination'
This happens because the serializer doesn't know what type to cast to since the types that throw the error can be of more than one type. I think that simplifies the XML but it makes the WSDL/.NET stuff more complicated. I'm probably not saying that perfectly accurately but that's the gist of it, at least as I understand it.
You can go into your reference.cs file and remove the serialization for those offending fields and try again. I've done this in the past with some success. If/when you update the API version with a new WSDL file you'll have to remember to do it again, though, so it's not a perfect solution. I've got a sample of what I removed from my reference.cs file to get one of the profile APIs below, hopefully it's helpful.
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.7.3056.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.sabre.com/eps/schemas")]
public partial class BusinessSystemIdentityInfoSynchronizationCriterionType {
private BusinessSystemIdentityInfoSynchronizationCriterionTypeExcludeCombination[] itemsField;
private ItemsChoiceType1[] itemsElementNameField;
//remarked this out 12/24/18 - these include/exclude combinations do not serialize correctly for some reason
/// <remarks/>
//[System.Xml.Serialization.XmlElementAttribute("ExcludeCombination", typeof(BusinessSystemIdentityInfoSynchronizationCriterionTypeExcludeCombination))]
//[System.Xml.Serialization.XmlElementAttribute("IncludeCombination", typeof(BusinessSystemIdentityInfoSynchronizationCriterionTypeIncludeCombination))]
//[System.Xml.Serialization.XmlChoiceIdentifierAttribute("ItemsElementName")]
//public BusinessSystemIdentityInfoSynchronizationCriterionTypeExcludeCombination[] Items {
// get {
// return this.itemsField;
// }
// set {
// this.itemsField = value;
// }
//}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("ItemsElementName")]
[System.Xml.Serialization.XmlIgnoreAttribute()]
public ItemsChoiceType1[] ItemsElementName {
get {
return this.itemsElementNameField;
}
set {
this.itemsElementNameField = value;
}
}
}
The below given is snipet of the ccode i am facing trouble with and i am using jdk 8. I am facing error in the bold line of the code , for loop statement. I have mentioned the error too.:
do {
jobid = br.readLine();
metajson = br.readLine();
JSONObject obj = (JSONObject) jsonParser.parse(metajson);
System.out.println(jobid+" "+obj.toString());
//The below one should work
****for (HashMap.Entry<String, String> entry : obj.entrySet())****
{
System.out.println(entry.getKey() + "/" + entry.getValue());
}
}
Error:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
PropertyEntry cannot be resolved to a type
Duplicate local variable entry
Entry cannot be resolved to a type
at com.journaldev.json.Insert3.main(Insert3.java:64)
a error at this line that says "Type mismatch: cannot convert from element type Object to Map.Entry>"
I tried the Property.Map() and concept.Map() too, but the same issue is there. I also imported the whole collection class too. But i don't know the error is not resolving.
Because the returned set of entries has a type of <String, JSONObject> instead of <String, String> .
The following code compiles:
Set<Entry<String, JSONObject>> entrySet = jsonObject.entrySet();
for (Entry<String, JSONObject> entry : entrySet) {
String key = entry.getKey();
JSONObject innerJsonObject = entry.getValue();
}
Anyway that library (simple-json) has a bad design. JsonObject inherits itself from HashMap raw type (without filling it's generic type declaration) so the resulting entrySet's type is not known at compile time.
Tip: Use GSon or other json library instead of that.
Following line of code gives me an error saying "The underlying connection was closed".
return this.repository.GetQuery<Countries>().Include(g => g.Cities).AsEnumerable().ToList();
But if I remove .Include(g => g.cities) it works fine.
this code is written in one of the operation in my WCF service, and I try to test it using WCF test client. I tried by calling this operation from MVC application also, and the same issue was occurring there too.
Also, i am using generic repository with entity framework
Repository code (only few important extract)
Constructor:
public GenericRepository(DbContext objectContext)
{
if (objectContext == null)
throw new ArgumentNullException("objectContext");
this._dbContext = objectContext;
this._dbContext.Configuration.LazyLoadingEnabled = false;
this._dbContext.Configuration.ProxyCreationEnabled = false;
}
GetQuery method:
public IQueryable<TEntity> GetQuery<TEntity>() where TEntity : class
{
var entityName = GetEntityName<TEntity>();
return ((IObjectContextAdapter)DbContext).ObjectContext.CreateQuery<TEntity>(entityName);
}
Attempt#1
Created following overloads in repository code:
public IQueryable<TEntity> GetQuery<TEntity>(params string[] includes) where TEntity : class
{
var entityName = GetEntityName<TEntity>();
IQueryable<TEntity> query = ((IObjectContextAdapter)DbContext).ObjectContext.CreateQuery<TEntity>(entityName);
foreach(string include in includes)
{
query = query.Include(include);
}
return query;
}
public IQueryable<TEntity> GetQuery<TEntity>(Expression<Func<TEntity, bool>> predicate, params string[] includes) where TEntity : class
{
return GetQuery<TEntity>(includes).Where(predicate);
}
WCF is now trying to execute following line of code:
return this.repository.GetQuery<Countries>("Cities").AsEnumerable().ToList()
But it still gives the same error of "The underlying connection was closed". I tested it in WCF test client. However, when I debug the repository code it shows the navigation object getting included in result, but the issue seems occurring while trying to pass the output to client (WCF test client, or any other client)
After looking at the code you've now posted, I can conclude that, indeed, your DbContext is being closed at the end of the GetQuery method, and is thus failing when you try to use include. What you might want to do to solve it is to have an optional params variable for the GetQuery method that will take in some properties to be included, and just do the include right in the GetQuery method itself.
Are there any tools available, or perhaps utility methods within NHibernate, which may help me to nail down which mapping is throwing a "The given key is not present in the dictionary"?
I understand that I must have a bad mapping, but I have hundreds of domain objects. What can I do to locate the source of my error more quickly?
From the NHibernate 2.1.2GA Source:
private PersistentClass GetPersistentClass(string className)
{
PersistentClass pc = configuration.classes[className]; // <- "The given key was not present in the dictionary"
if (pc == null)
{
throw new MappingException("persistent class not known: " + className);
}
return pc;
}
And in this case, className is System.Int32.
Ok, so I had an int field marked <many-to-one> instead of <property>. I ended up digging up the source for NH and debugging to get to this point.
NHibernate Mapping: Creating Sanity Checks
[Test]
public void AllNHibernateMappingAreOkay()
{
IDictionary allClassMetadata = session.SessionFactory.GetAllClassMetadata();
foreach (DictionaryEntry entry in allClassMetadata)
{
session
.CreateCriteria((Type) entry.Key)
.SetMaxResults(0)
.List();
}
}