0

I have a class with a property:

virtual public string Data { get; set; }

example.hbm.xml binds that to:

<property name="Data" type="string" column="data" ></property>

The table in MySql is created with:

CREATE TABLE `xxx` (
 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
 `data` blob,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=binary;

I can successfully write to the db and I can see the text in the column written properly.

When I try to read records from this table the value of the 'Data' property is 'System.Byte[]'. Again this is the value of this property. It's type is 'System.String'.

What to do? Thanks in advance for any clues.

I tried charset=UTF8 too.

I also tried type="StringClob" in the mapping file.

Thanks Tymek

2 Answers 2

3

You probably need to read and write this as a byte[]. So you're property definition would look like this instead:

public virtual byte[] Data { get; set; }

In addition to this change you will need to change the type in your mapping. I'm not sure what the type. I think it may be blob.

You can easily convert this data to a string if you need to.

Sign up to request clarification or add additional context in comments.

Comments

1

I'm no MySQL expert, but you probably want the column type to be text instead of blob.

With that, type="StringClob" should work

2 Comments

You are totally right, but as the db schema is already in place I'll mark "read it as byte[]" as the best answer.
@Tymek: that's fine. Keep in mind you'll have to use an Encoding if you want to read it as text.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.